]> mj.ucw.cz Git - libucw.git/commitdiff
add strnlen() which isn't available on Darwin
authorRobert Spalek <rspalek@gmail.com>
Sat, 11 Apr 2009 20:12:42 +0000 (13:12 -0700)
committerRobert Spalek <rspalek@gmail.com>
Sat, 11 Apr 2009 20:12:42 +0000 (13:12 -0700)
now all tests pass

ucw/stkstring.c
ucw/stkstring.h

index 32bd974336c36e4781612f776b1657eb42e9f58f..e501ba20fabe4d47f04e892d47a2d7b4c45e0214 100644 (file)
 
 #include <stdio.h>
 
+#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)
 {
index d0d6ad7f34bdc5a2ad412817f05aaa2051b53b5e..d96b72386adc703040e8db3e0e73b7f1b3882f46 100644 (file)
 #include <string.h>
 #include <stdio.h>
 
+#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; })