diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-03-07 09:46:17 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-03-07 16:36:11 -0800 |
commit | 0b8deb2a15d4785fb8bd6cd67a913ecd4d8e02c8 (patch) | |
tree | 89c2f21f01a1602ef0afec52155a7e51439a95a7 /membuffer.c | |
parent | 4edf37f9be0374c73ae957c09b393f5bc913fe3f (diff) | |
download | subsurface-0b8deb2a15d4785fb8bd6cd67a913ecd4d8e02c8.tar.gz |
Add C string helper to membuffer interface
I don't know why I didn't do this from the beginning. We often build up
a membuffer and then want to use it as a C string. You could do it by
hand by adding the zero byte at the end, but that's just annoying.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'membuffer.c')
-rw-r--r-- | membuffer.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/membuffer.c b/membuffer.c index fd179244b..8ba23ebe2 100644 --- a/membuffer.c +++ b/membuffer.c @@ -55,6 +55,13 @@ static void make_room(struct membuffer *b, unsigned int size) } } +const char *mb_cstring(struct membuffer *b) +{ + make_room(b, 1); + b->buffer[b->len] = 0; + return b->buffer; +} + void put_bytes(struct membuffer *b, const char *str, int len) { make_room(b, len); |