diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-02-09 09:40:49 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-10 07:03:25 -0800 |
commit | 77da20196f3efe8eaf4a7bd898f0c6206d146c61 (patch) | |
tree | a31532d8d1e3410fd23b5af1d3b29c1b612d07bf /membuffer.h | |
parent | 22f66501ac4075084c0fd1d0b0d943aa92df1306 (diff) | |
download | subsurface-77da20196f3efe8eaf4a7bd898f0c6206d146c61.tar.gz |
Clean up membuffer internal structure names, add strip function
The "size" member was confusing - it's the size of the allocation, not
the size of the current string. The size of the current string is the
member called "used".
This naming makes perfect sense for the internal implementation, but
it's confusing to users who actually do want to get the size of the
resulting string at the end.
So rename the fields to "alloc" and "len" - which is pretty clear.
This also adds a helper function to strip whitespace from the end:
"strip_mb()".
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'membuffer.h')
-rw-r--r-- | membuffer.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/membuffer.h b/membuffer.h index bef9e76bc..17cfe6e8c 100644 --- a/membuffer.h +++ b/membuffer.h @@ -1,8 +1,14 @@ #ifndef MEMBUFFER_H #define MEMBUFFER_H +#ifdef __cplusplus +extern "C" { +#endif + +#include <ctype.h> + struct membuffer { - unsigned int size, used; + unsigned int len, alloc; char *buffer; }; @@ -16,6 +22,7 @@ extern void free_buffer(struct membuffer *); extern void flush_buffer(struct membuffer *, FILE *); extern void put_bytes(struct membuffer *, const char *, int); extern void put_string(struct membuffer *, const char *); +extern void strip_mb(struct membuffer *); extern __printf(2,0) void put_vformat(struct membuffer *, const char *, va_list); extern __printf(2,3) void put_format(struct membuffer *, const char *fmt, ...); @@ -49,4 +56,8 @@ extern int put_duration(struct membuffer *, duration_t, const char *, const char extern int put_pressure(struct membuffer *, pressure_t, const char *, const char *); extern int put_salinity(struct membuffer *, int, const char *, const char *); +#ifdef __cplusplus +} +#endif + #endif |