repo: ngircd action: commit revision: path_from: revision_from: f024a4992a9a38d64d0fd63283cd0c484bdec683: path_to: revision_to:
commit f024a4992a9a38d64d0fd63283cd0c484bdec683 Author: Alexander BartonDate: Wed Jan 1 16:38:36 2014 +0100 portabtest: Add checks for strdup(), strndup(), and strtok_r() diff --git a/src/portab/portabtest.c b/src/portab/portabtest.c
--- a/src/portab/portabtest.c
+++ b/src/portab/portabtest.c
@@ -44,6 +44,36 @@ Check_snprintf(void)
Panic("snprintf string length");
}
+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)
{
@@ -72,6 +102,30 @@ Check_strlcat(void)
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, ...)
@@ -118,8 +172,11 @@ main(void)
/* 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;
-----END OF PAGE-----