X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrndup.c;h=446fb5d6a6ac87e0fc9aeed516a27ae81931ac3b;hp=e50f419ded982705b0e9e5530299f080c0a40f54;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=219271fd548949abce8bd75c34dd42e519418fc4 diff --git a/functions/string/strndup.c b/functions/string/strndup.c index e50f419..446fb5d 100644 --- a/functions/string/strndup.c +++ b/functions/string/strndup.c @@ -1,9 +1,13 @@ -/* [XSI] char* strndup(const char *, size_t) +/* [XSI] char * strndup( const char *, size_t ) 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 #include @@ -27,7 +31,7 @@ char *strndup( const char * s, size_t len ) #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" int main( void ) { @@ -37,16 +41,16 @@ int main( void ) 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);