X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=include%2Futils.h;h=1c634d81529f4bf382f1e7a4ce5834de7b45f7c0;hb=302a260054ea38d3cb97be6d1a3010082c09265d;hp=a1176a6379e17ed30fb8c003e035ae49bcd5aef9;hpb=735f4b1a8de997d577d2fb9ecef23974d5e7dac6;p=doldaconnect.git diff --git a/include/utils.h b/include/utils.h index a1176a6..1c634d8 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,6 +1,6 @@ /* * Dolda Connect - Modular multiuser Direct Connect-style client - * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) + * Copyright (C) 2004 Fredrik Tolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,13 +31,18 @@ struct wcspair { wchar_t *val; }; +struct strpair { + struct strpair *next; + char *key; + char *val; +}; /* "Safe" functions */ #ifdef DAEMON #define LOGOOM(size) flog(LOG_CRIT, "%s (%s:%i): out of memory (alloc %zi)", __FUNCTION__, __FILE__, __LINE__, (size)) #define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({LOGOOM((ssize_t)(size)); abort(); (void *)0;}):__result__;}) #define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({LOGOOM((ssize_t)(size)); abort(); (void *)0;}):__result__;}) -#define swcsdup(wcs) ((wchar_t *)wcscpy(smalloc(sizeof(wchar_t) * (wcslen(wcs) + 1)), (wcs))) +#define swcsdup(wcs) ({wchar_t *__eval__; __eval__ = (wcs); (wchar_t *)wcscpy(smalloc(sizeof(wchar_t) * (wcslen(__eval__) + 1)), __eval__);}) #define sstrdup(str) ((char *)strcpy(smalloc(strlen(str) + 1), (str))) #else #define LOGOOM(size) @@ -101,6 +106,9 @@ char *base32decode(char *data, size_t *datalen); void _freeparr(void **arr); int _parrlen(void **arr); char *findfile(char *name, char *homedir, int filldef); +struct strpair *newstrpair(char *key, char *val, struct strpair **list); +void freestrpair(struct strpair *pair, struct strpair **list); +char *spfind(struct strpair *list, char *key); struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list); void freewcspair(struct wcspair *pair, struct wcspair **list); wchar_t *wpfind(struct wcspair *list, wchar_t *key); @@ -120,6 +128,13 @@ do { \ memcpy((d) + (d ## data), (s), sizeof(*(d)) * __bufcat_size__); \ (d ## data) += __bufcat_size__; \ } while (0) +#define bprintf(b, fmt...) \ + do { \ + char *__bprintf_dest__; \ + __bprintf_dest__ = sprintf2(fmt); \ + bufcat(b, __bprintf_dest__, strlen(__bprintf_dest__)); \ + free(__bprintf_dest__); \ + } while(0) #define freeparr(parr) _freeparr((void **)(parr)) #define parrlen(parr) _parrlen((void **)(parr))