Sigridwip3f1816d8 years agoHistory
52 lines · 695 B · C
RawDownload
#include <string.h>#include "util.h"#include "mem.h"#include "buf.h" buf_t *buf_alloc(mem_pool_t *pool){	buf_t *b; 	b = mem_alloc(pool, sizeof(*b));	memset(b, 0, sizeof(*b));	b->pool = pool; 	return b;} intbuf_write(buf_t *b, const void *data, int sz){	int nsz, npow2; 	nsz = b->sz + sz;	npow2 = next_pow2(nsz);	if (b->next_pow2 <= npow2) {		b->next_pow2 = npow2;		b->data = mem_realloc(b->pool, b->data, npow2);	}	memmove((char*)b->data + b->sz, data, sz);	b->sz = nsz; 	return nsz;} intbuf_puts(buf_t *b, const char *s){	return buf_write(b, s, strlen(s));} voidbuf_clear(buf_t *b){	b->sz = 0;} voidbuf_free(buf_t *b){	mem_free(b->data);	mem_free(b);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t