]> Pileus Git - lackey/blobdiff - src/util.c
Use CURL simple API for EWS calendars
[lackey] / src / util.c
index d74a7469d0914c23a909140066c95ec3d501775d..2f11d078f8a90d431cc1675dfdd96f6e305712ef 100644 (file)
@@ -106,6 +106,27 @@ void *alloc0(int size)
        return data;
 }
 
+void append(buf_t *buf, const void *data, int len)
+{
+       if (buf->len + len + 1 > buf->max) {
+               buf->max += (((buf->len+len)/4096)+1)*4096;
+               buf->data = realloc(buf->data, buf->max);
+               if (!buf->data)
+                       error("buffer reallocation allocation failed");
+       }
+       memcpy(buf->data + buf->len, data, len);
+       buf->len += len;
+       ((char*)buf->data)[buf->len] = '\0';
+}
+
+void release(buf_t *buf)
+{
+       free(buf->data);
+       buf->data = 0;
+       buf->len  = 0;
+       buf->max  = 0;
+}
+
 /* File functions */
 char *read_file(const char *path, int *len)
 {