From: Robert Spalek Date: Sat, 11 Apr 2009 20:12:42 +0000 (-0700) Subject: add strnlen() which isn't available on Darwin X-Git-Tag: holmes-import~25 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=733046c9a1a6ccc33617d73238c3c8f4865b34a4;p=libucw.git add strnlen() which isn't available on Darwin now all tests pass --- diff --git a/ucw/stkstring.c b/ucw/stkstring.c index 32bd9743..e501ba20 100644 --- a/ucw/stkstring.c +++ b/ucw/stkstring.c @@ -15,6 +15,17 @@ #include +#ifdef CONFIG_DARWIN +uns +strnlen(const char *str, uns n) +{ + const char *end = str + n; + const char *c; + for (c = str; *c && c < end; c++); + return c - str; +} +#endif + uns stk_array_len(char **s, uns cnt) { diff --git a/ucw/stkstring.h b/ucw/stkstring.h index d0d6ad7f..d96b7238 100644 --- a/ucw/stkstring.h +++ b/ucw/stkstring.h @@ -16,6 +16,10 @@ #include #include +#ifdef CONFIG_DARWIN +uns strnlen(const char *str, uns n); +#endif + #define stk_strdup(s) ({ const char *_s=(s); uns _l=strlen(_s)+1; char *_x=alloca(_l); memcpy(_x, _s, _l); _x; }) #define stk_strndup(s,n) ({ const char *_s=(s); uns _l=strnlen(_s,(n)); char *_x=alloca(_l+1); memcpy(_x, _s, _l); _x[_l]=0; _x; }) #define stk_strcat(s1,s2) ({ const char *_s1=(s1); const char *_s2=(s2); uns _l1=strlen(_s1); uns _l2=strlen(_s2); char *_x=alloca(_l1+_l2+1); memcpy(_x,_s1,_l1); memcpy(_x+_l1,_s2,_l2+1); _x; })