aboutsummaryrefslogtreecommitdiff
path: root/lib/bob/u8strinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bob/u8strinit.c')
-rw-r--r--lib/bob/u8strinit.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/bob/u8strinit.c b/lib/bob/u8strinit.c
new file mode 100644
index 0000000..60423c1
--- /dev/null
+++ b/lib/bob/u8strinit.c
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+
+#include "bob.h"
+
+struct u8str *
+u8strinit(struct u8str *b, size_t n)
+{
+ if (n) {
+ if (!(b->p = malloc(n)))
+ return nullptr;
+ } else
+ b->p = nullptr;
+ b->len = 0;
+ b->cap = n;
+ return b;
+}