7 #define max(a, b) (((b) > (a))?(b):(a))
8 #define min(a, b) (((b) < (a))?(b):(a))
10 #define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;})
11 #define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;})
12 #define szmalloc(size) memset(smalloc(size), 0, size)
13 #define sstrdup(str) ({const char *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);})
14 #define omalloc(o) ((o) = szmalloc(sizeof(*(o))))
16 #define bufinit(buf) memset(&(buf), 0, sizeof(buf))
17 #define buffree(buf) do { if((buf).b != NULL) {free((buf).b);} bufinit(buf); } while(0)
18 #define sizebuf(buf, wanted) (_sizebuf((struct buffer *)&(buf), (wanted), sizeof(*((buf).b))))
19 #define bufadd(buf, new) \
21 _sizebuf((struct buffer *)&(buf), (buf).d + 1, sizeof(*((buf).b))); \
22 (buf).b[(buf).d++] = (new); \
24 #define bufcat(buf, new, size) \
26 size_t __bufcat_size__; \
27 __bufcat_size__ = (size); \
28 _sizebuf((struct buffer *)&(buf), (buf).d + __bufcat_size__, sizeof((buf).b)); \
29 memcpy((buf).b + (buf).d, (new), (__bufcat_size__) * sizeof(*((buf).b))); \
30 (buf).d += __bufcat_size__; \
32 #define bufcatstr(buf, str) \
36 bufcat((buf), __buf__, strlen(__buf__)); \
38 #define bufcatstr2(buf, str) \
42 bufcat((buf), __buf__, strlen(__buf__) + 1); \
44 #define bufeat(buf, len) memmove((buf).b, (buf).b + (len), (buf).d -= (len))
51 #define typedbuf(type) struct {type *b; size_t s, d;}
63 void _sizebuf(struct buffer *buf, size_t wanted, size_t el);
64 char *decstr(char **p, size_t *len);
65 char *vsprintf2(char *format, va_list al);
66 char *sprintf2(char *format, ...);
67 char *sprintf3(char *format, ...);
69 char **tokenize(char *src);
70 void freeca(char **ca);
72 void bvprintf(struct charbuf *buf, char *format, va_list al);
73 void bprintf(struct charbuf *buf, char *format, ...);
74 void replstr(char **p, char *n);
75 char *base64encode(char *data, size_t datalen);
76 char *base64decode(char *data, size_t *datalen);