]> pd.if.org Git - pdclib/blobdiff - functions/string/strndup.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / string / strndup.c
index e25c7ed967855955b824c27443f4f31817abc44f..446fb5d6a6ac87e0fc9aeed516a27ae81931ac3b 100644 (file)
@@ -1,9 +1,13 @@
-/* [XSI] char* strndup(const char *, size_t)\r
+/* [XSI] char * strndup( const char *, size_t )\r
 \r
    This file is part of the Public Domain C Library (PDCLib).\r
    Permission is granted to use, modify, and / or redistribute at will.\r
 */\r
 \r
+#ifdef REGTEST\r
+#define _POSIX_C_SOURCE 200809L\r
+#endif\r
+\r
 #include <string.h>\r
 #include <stdlib.h>\r
 \r
@@ -27,29 +31,32 @@ char *strndup( const char * s, size_t len )
 #endif\r
 \r
 #ifdef TEST\r
-#include <_PDCLIB_test.h>\r
+#include "_PDCLIB_test.h"\r
 \r
 int main( void )\r
 {\r
+#ifndef REGTEST\r
+    /* Missing on Windows. Maybe use conditionals? */\r
     const char *teststr  = "Hello, world";\r
     const char *teststr2 = "\xFE\x8C\n";\r
     char *testres, *testres2;\r
 \r
-    TESTCASE(testres  = strndup(teststr, 5));\r
-    TESTCASE(testres2 = strndup(teststr2, 1));\r
+    TESTCASE((testres  = strndup(teststr, 5)) != NULL);\r
+    TESTCASE((testres2 = strndup(teststr2, 1)) != NULL);\r
     TESTCASE(strcmp(testres, teststr) != 0);\r
     TESTCASE(strncmp(testres, teststr, 5) == 0);\r
     TESTCASE(strcmp(testres2, teststr2) != 0);\r
     TESTCASE(strncmp(testres2, teststr2, 1) == 0);\r
     free(testres);\r
     free(testres2);\r
-    TESTCASE(testres  = strndup(teststr, 20));\r
-    TESTCASE(testres2 = strndup(teststr2, 5));\r
+    TESTCASE((testres  = strndup(teststr, 20)) != NULL);\r
+    TESTCASE((testres2 = strndup(teststr2, 5)) != NULL);\r
     TESTCASE(strcmp(testres, teststr) == 0);\r
     TESTCASE(strcmp(testres2, teststr2) == 0);\r
     free(testres);\r
     free(testres2);\r
-    \r
+#endif\r
+\r
     return TEST_RESULTS;\r
 }\r
 \r