kst/ke/abuf.c

28 lines
357 B
C
Raw Normal View History

2020-02-11 17:52:49 +00:00
#include <stdlib.h>
#include <string.h>
2020-02-12 00:38:06 +00:00
#include "defs.h"
2020-02-11 17:52:49 +00:00
void
ab_append(struct abuf *buf, const char *s, int len)
{
char *nc = realloc(buf->b, buf->len + len);
if (nc == NULL) {
abort();
}
memcpy(&nc[buf->len], s, len);
buf->b = nc;
buf->len += len; /* DANGER: overflow */
}
void
ab_free(struct abuf *buf)
{
free(buf->b);
buf->b = NULL;
}