X-Git-Url: http://git.thejh.net/?p=libjh.git;a=blobdiff_plain;f=string.c;h=41082f10d2ef13bc95f3bb3f76e6f5d131c3c56b;hp=b0db54c0fac7f8f38df1cb9071e18c11991aa2d8;hb=ae33d7fe92d8dd8593e7a2b938d1f42d2aa60896;hpb=4455aa6469db5cc86ff175ab0b6eafbe75a16ea4 diff --git a/string.c b/string.c index b0db54c..41082f1 100644 --- a/string.c +++ b/string.c @@ -1,12 +1,24 @@ // Copyright (2013) Jann Horn -// This code is licensed under the AGPLv3. -#include +#ifdef __SSE2__ #include +#endif + +#include HEADER #include HEADER #define streq(a,b) (!strcmp((a),(b))) +HEADER #define TPRINTF(name, ...) \ +HEADER char *name; \ +HEADER do { \ +HEADER int __tprintf_size = snprintf(NULL, 0, __VA_ARGS__); \ +HEADER assert(__tprintf_size != -1); \ +HEADER name = alloca(__tprintf_size+1); \ +HEADER int __tprintf_size2 = snprintf(name, __tprintf_size+1, __VA_ARGS__); \ +HEADER assert(__tprintf_size == __tprintf_size2); \ +HEADER } while (0); ////////////////////////////////////////////////////////// + PUBLIC_FN int count_char_occurences(char *s, char c) { int n=0; while (*s) { @@ -22,7 +34,6 @@ PUBLIC_FN size_t count_char_occurences_in_buf(char *b, size_t bl, char c) { size_t res = 0; #ifdef __SSE2__ - #include // do it the simple way until we get to the next 16-byte-aligned address while ((((uint64_t)b)&0xf) && b // do it the simple way until we get to the next 16-byte-aligned address while ((((uint64_t)b)&0xf) && b