X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=lib%2Futils.h;h=3c9800c6ec5b154dce6a43c8e2484e153bb9299a;hp=d74d09d84d26f20388b6ef091dc194276b30e4a8;hb=90f6e953d2d2f905675aadbaf5e307e24c586edd;hpb=41213112d34e04d3d088600c6b5eafeaab21330c diff --git a/lib/utils.h b/lib/utils.h index d74d09d..3c9800c 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -1,10 +1,12 @@ #ifndef _UTILS_H #define _UTILS_H +#include + #define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;}) #define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;}) #define szmalloc(size) memset(smalloc(size), 0, size) -#define sstrdup(str) ({char *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);}) +#define sstrdup(str) ({const char *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);}) #define omalloc(o) ((o) = szmalloc(sizeof(*(o)))) #define bufinit(buf) memset(&(buf), 0, sizeof(buf)) @@ -23,12 +25,19 @@ do { \ memcpy((buf).b + (buf).d, (new), (__bufcat_size__) * sizeof(*((buf).b))); \ (buf).d += __bufcat_size__; \ } while(0) -#define bufcatstr2(buf, str) \ +#define bufcatstr(buf, str) \ do { \ char *__buf__; \ __buf__ = (str); \ bufcat((buf), __buf__, strlen(__buf__)); \ } while(0) +#define bufcatstr2(buf, str) \ +do { \ + char *__buf__; \ + __buf__ = (str); \ + bufcat((buf), __buf__, strlen(__buf__) + 1); \ +} while(0) +#define bufeat(buf, len) memmove((buf).b, (buf).b + (len), (buf).d -= (len)) struct buffer { void *b; @@ -48,5 +57,9 @@ struct charvbuf { }; 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); +char *sprintf2(char *format, ...); +char *sprintf3(char *format, ...); #endif