X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Futils.h;h=2de1df6b68edae85f8c1e8b0d8c313e09cda41e0;hb=ae13a8b18216c45b0e75060a4df65659e572822a;hp=78241b35c3b6a9e21fb366de8dd4269d50c24899;hpb=d422fdfd62d851b345562ad4d093465d2bec604b;p=ashd.git diff --git a/lib/utils.h b/lib/utils.h index 78241b3..2de1df6 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -2,6 +2,7 @@ #define _UTILS_H #include +#include #define max(a, b) (((b) > (a))?(b):(a)) #define min(a, b) (((b) < (a))?(b):(a)) @@ -13,7 +14,7 @@ #define omalloc(o) ((o) = szmalloc(sizeof(*(o)))) #define bufinit(buf) memset(&(buf), 0, sizeof(buf)) -#define buffree(buf) do { if((buf).b != NULL) {free((buf).b);} } while(0) +#define buffree(buf) do { if((buf).b != NULL) {free((buf).b);} bufinit(buf); } while(0) #define sizebuf(buf, wanted) (_sizebuf((struct buffer *)&(buf), (wanted), sizeof(*((buf).b)))) #define bufadd(buf, new) \ do { \ @@ -59,6 +60,12 @@ struct charvbuf { size_t s, d; }; +struct btree { + struct btree *l, *r; + int h; + void *d; +}; + void _sizebuf(struct buffer *buf, size_t wanted, size_t el); char *decstr(char **p, size_t *len); char *vsprintf2(char *format, va_list al); @@ -70,5 +77,12 @@ void freeca(char **ca); int calen(char **a); void bvprintf(struct charbuf *buf, char *format, va_list al); void bprintf(struct charbuf *buf, char *format, ...); +void replstr(char **p, char *n); +char *base64encode(char *data, size_t datalen); +char *base64decode(char *data, size_t *datalen); +int bbtreedel(struct btree **tree, void *item, int (*cmp)(void *, void *)); +void freebtree(struct btree **tree, void (*ffunc)(void *)); +int bbtreeput(struct btree **tree, void *item, int (*cmp)(void *, void *)); +void *btreeget(struct btree *tree, void *key, int (*cmp)(void *, void *)); #endif