1 /* adbuf.h - header file for adbuf.c 2 * 3 * Copyright(C) 2001-2002 Salvatore Sanfilippo <antirez@invece.org> 4 * All rights reserved. 5 * See the LICENSE file for COPYRIGHT and PERMISSION notice */ 6 7 /* $Id: adbuf.h,v 1.1.1.1 2003/08/31 17:24:00 antirez Exp $ */ 8 9 #ifndef _ADBUF_H 10 #define _ADBUF_H 11 12 #include <sys/types.h> 13 14 struct adbuf { 15 char *buf; 16 size_t size; /* total buffer size */ 17 size_t left; /* unused buffer size */ 18 /* the size of data stored is just size-left */ 19 }; 20 21 #define ADBUF_INCR 256 /* note that this MUST BE >= 1 */ 22 #define adbuf_used(b) ((b)->size - (b)->left) 23 #define adbuf_ptr(b) ((b)->buf) 24 25 /* Rawly create an adbuf object. 's' is supposed to be some heap 26 * memory already allocated, with some nul-term string inside */ 27 #define adbuf_from_heapstring(b,s) \ 28 do { b->buf = s; b->left = 0; b->size = strlen(s); } while(0) 29 30 int adbuf_init(struct adbuf *b); 31 void adbuf_free(struct adbuf *b); 32 int adbuf_reset(struct adbuf *b); 33 int adbuf_add(struct adbuf *b, void *data, size_t len); 34 int adbuf_addchar(struct adbuf *b, int c); 35 int adbuf_strcat(struct adbuf *b, char *string); 36 int adbuf_cat(struct adbuf *a, struct adbuf *b); 37 int adbuf_cut(struct adbuf *b, size_t count); 38 int adbuf_ltrim(struct adbuf *b, size_t count); 39 int adbuf_rtrim(struct adbuf *b, size_t count); 40 int adbuf_add_long(struct adbuf *b, long l); 41 int adbuf_add_ulong(struct adbuf *b, unsigned long l); 42 int adbuf_clone(struct adbuf *src, struct adbuf *dst); 43 int adbuf_printf(struct adbuf *dst, const char *fmt, ...); 44 45 #endif /* _ADBUF_H */ 46