]> pd.if.org Git - pdclib/blobdiff - functions/string/strdup.c
dos2unix
[pdclib] / functions / string / strdup.c
index bbd1e93be1c0485f6b61be1b312f4b09c0540d17..78dd01d4f645f3e49215fdd0b45f4cac794a62d3 100644 (file)
@@ -1,49 +1,49 @@
-/* [XSI] char * strdup( const char * )\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
-#ifndef REGTEST\r
-\r
-char *strdup(const char *s)\r
-{\r
-    char* ns = NULL;\r
-    if(s) {\r
-        size_t len = strlen(s) + 1;\r
-        ns = malloc(len);\r
-        if(ns)\r
-            strncpy(ns, s, len);\r
-    }\r
-    return ns;\r
-}\r
-\r
-#endif\r
-\r
-#ifdef TEST\r
-#include "_PDCLIB_test.h"\r
-\r
-int main( void )\r
-{\r
-    const char *teststr  = "Hello, world";\r
-    const char *teststr2 = "An alternative test string with non-7-bit characters \xFE\x8C\n";\r
-    char *testres, *testres2;\r
-\r
-    TESTCASE((testres  = strdup(teststr)) != NULL);\r
-    TESTCASE((testres2 = strdup(teststr2)) != NULL);\r
-    TESTCASE(strcmp(testres, teststr) == 0);\r
-    TESTCASE(strcmp(testres2, teststr2) == 0);\r
-    free(testres);\r
-    free(testres2);\r
-\r
-    return TEST_RESULTS;\r
-}\r
-\r
-#endif\r
+/* [XSI] char * strdup( const char * )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#ifdef REGTEST
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef REGTEST
+
+char *strdup(const char *s)
+{
+    char* ns = NULL;
+    if(s) {
+        size_t len = strlen(s) + 1;
+        ns = malloc(len);
+        if(ns)
+            strncpy(ns, s, len);
+    }
+    return ns;
+}
+
+#endif
+
+#ifdef TEST
+#include "_PDCLIB_test.h"
+
+int main( void )
+{
+    const char *teststr  = "Hello, world";
+    const char *teststr2 = "An alternative test string with non-7-bit characters \xFE\x8C\n";
+    char *testres, *testres2;
+
+    TESTCASE((testres  = strdup(teststr)) != NULL);
+    TESTCASE((testres2 = strdup(teststr2)) != NULL);
+    TESTCASE(strcmp(testres, teststr) == 0);
+    TESTCASE(strcmp(testres2, teststr2) == 0);
+    free(testres);
+    free(testres2);
+
+    return TEST_RESULTS;
+}
+
+#endif