aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 20:45:58 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 20:45:58 +0100
commit71cb8291d7dc27798c58e1d4fbb28ceee3f07532 (patch)
tree325beb656b40df536a623ad1c56cb089792aa54a /strbuf.c
parentSimplify Makefiel. (diff)
downloadcalp-71cb8291d7dc27798c58e1d4fbb28ceee3f07532.tar.gz
calp-71cb8291d7dc27798c58e1d4fbb28ceee3f07532.tar.xz
Strbuf remove init_1, add strbuf_load.
Diffstat (limited to '')
-rw-r--r--strbuf.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/strbuf.c b/strbuf.c
index 9160e02a..f3becfc7 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -6,16 +6,8 @@
#include "err.h"
INIT_F(strbuf) {
- INIT(strbuf, self, 1);
- return 0;
-}
-
-/*
- * Giving len < 1 is an error.
- */
-INIT_F(strbuf, size_t len) {
- self->mem = (char*) calloc(sizeof(*self->mem), len);
- self->alloc = len;
+ self->alloc = 0x10;
+ self->mem = (char*) calloc(sizeof(*self->mem), self->alloc);
self->ptr = 0;
self->len = 0;
self->scm = NULL;
@@ -143,3 +135,11 @@ FMT_F(strbuf) {
int SIZE(strbuf)(strbuf* self) {
return self->len;
}
+
+int strbuf_load(strbuf* self, const char* str) {
+ for (int i = 0; str[i] != '\0'; i++) {
+ strbuf_append(self, str[i]);
+ }
+ strbuf_cap(self);
+ return 0;
+}