X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrndup.c;h=15c44be27f23dc717acc718dd8dddb60f7e28bdf;hp=e25c7ed967855955b824c27443f4f31817abc44f;hb=5b64e18a94a184cc73392d563a1f3e0dbd3bdbf8;hpb=1cc4363093c919f79eafac209bb5c41548d3f88f diff --git a/functions/string/strndup.c b/functions/string/strndup.c index e25c7ed..15c44be 100644 --- a/functions/string/strndup.c +++ b/functions/string/strndup.c @@ -4,6 +4,10 @@ Permission is granted to use, modify, and / or redistribute at will. */ +#ifdef REGTEST +#define _POSIX_C_SOURCE 200809L +#endif + #include #include @@ -31,25 +35,28 @@ char *strndup( const char * s, size_t len ) int main( void ) { +#ifndef REGTEST + /* Missing on Windows. Maybe use conditionals? */ const char *teststr = "Hello, world"; const char *teststr2 = "\xFE\x8C\n"; char *testres, *testres2; - TESTCASE(testres = strndup(teststr, 5)); - TESTCASE(testres2 = strndup(teststr2, 1)); + TESTCASE((testres = strndup(teststr, 5)) != NULL); + TESTCASE((testres2 = strndup(teststr2, 1)) != NULL); TESTCASE(strcmp(testres, teststr) != 0); TESTCASE(strncmp(testres, teststr, 5) == 0); TESTCASE(strcmp(testres2, teststr2) != 0); TESTCASE(strncmp(testres2, teststr2, 1) == 0); free(testres); free(testres2); - TESTCASE(testres = strndup(teststr, 20)); - TESTCASE(testres2 = strndup(teststr2, 5)); + TESTCASE((testres = strndup(teststr, 20)) != NULL); + TESTCASE((testres2 = strndup(teststr2, 5)) != NULL); TESTCASE(strcmp(testres, teststr) == 0); TESTCASE(strcmp(testres2, teststr2) == 0); free(testres); free(testres2); - +#endif + return TEST_RESULTS; }