summaryrefslogtreecommitdiffstats
path: root/bstr/bstr.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-30 20:20:28 +0100
committerwm4 <wm4@nowhere>2013-12-30 22:49:50 +0100
commit097fe8ea6fb25df68077c25c08f29fb57a9d2bd6 (patch)
tree2c25042f0484fbdcec73f0c815af14828d7f164c /bstr/bstr.h
parent56ce2a39be53be9b06ba815c56d768d0e45f3ac3 (diff)
downloadmpv-097fe8ea6fb25df68077c25c08f29fb57a9d2bd6.tar.bz2
mpv-097fe8ea6fb25df68077c25c08f29fb57a9d2bd6.tar.xz
bstr: add bstr_xappend function
Apparently this can be really useful when being paranoid and trying to avoid too much malloc/realloc, since it can be used to appending into a buffer (with transparent realloc only if the buffer is too small).
Diffstat (limited to 'bstr/bstr.h')
-rw-r--r--bstr/bstr.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/bstr/bstr.h b/bstr/bstr.h
index 67e85655c4..71d5d473c4 100644
--- a/bstr/bstr.h
+++ b/bstr/bstr.h
@@ -23,8 +23,10 @@
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
+#include <stdarg.h>
#include "talloc.h"
+#include "compat/compiler.h"
/* NOTE: 'len' is size_t, but most string-handling functions below assume
* that input size has been sanity checked and len fits in an int.
@@ -118,6 +120,12 @@ struct bstr bstr_getline(struct bstr str, struct bstr *rest);
// and will remove the trailing \n or \r\n sequence.
struct bstr bstr_strip_linebreaks(struct bstr str);
+void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);
+void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
+ PRINTF_ATTRIBUTE(3, 4);
+void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
+ PRINTF_ATTRIBUTE(3, 0);
+
// If s starts with prefix, return true and return the rest of the string in s.
bool bstr_eatstart(struct bstr *s, struct bstr prefix);