commit - d38747d951a8a5007e97693cade3551e11e50569
commit + f024a4992a9a38d64d0fd63283cd0c484bdec683
blob - 4f53ce76594a27fa0d70a551c6e213e66899de47
blob + 9e6bd228bae0df847ab6d32fc52401d9bfc0aa37
--- src/portab/portabtest.c
+++ src/portab/portabtest.c
}
static void
+Check_strdup(void)
+{
+ char *ptr;
+
+ ptr = strdup("1234567890");
+ if (!ptr)
+ Panic("strdup");
+ if (ptr[10] != '\0')
+ Panic("strdup NULL byte");
+ if (strlen(ptr) != 10)
+ Panic("strdup string length");
+ free(ptr);
+}
+
+static void
+Check_strndup(void)
+{
+ char *ptr;
+
+ ptr = strndup("1234567890", 5);
+ if (!ptr)
+ Panic("strndup");
+ if (ptr[5] != '\0')
+ Panic("strndup NULL byte");
+ if (strlen(ptr) != 5)
+ Panic("strndup string length");
+ free(ptr);
+}
+
+static void
Check_strlcpy(void)
{
char str[5];
Panic("strlcat string length");
}
+static void
+Check_strtok_r(void)
+{
+ char *ptr, *last;
+
+ ptr = strdup("12,abc");
+
+ ptr = strtok_r(ptr, ",", &last);
+ if (!ptr)
+ Panic("strtok_r result #1");
+ if (strcmp(ptr, "12") != 0)
+ Panic("strtok_r token #1");
+
+ ptr = strtok_r(NULL, ",", &last);
+ if (!ptr)
+ Panic("strtok_r result #2");
+ if (strcmp(ptr, "abc") != 0)
+ Panic("strtok_r token #2");
+
+ ptr = strtok_r(NULL, ",", &last);
+ if (ptr)
+ Panic("strtok_r result #3");
+}
+
#ifdef PROTOTYPES
static void
Check_vsnprintf(const int Len, const char *Format, ...)
/* check functions */
Check_snprintf();
+ Check_strdup();
+ Check_strndup();
Check_strlcpy();
Check_strlcat();
+ Check_strtok_r();
Check_vsnprintf(2+10, "%s%s", "ab", "1234567890");
return 0;