4 * The canonical version of this file is maintained in the rra-c-util package,
5 * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
7 * Written by Russ Allbery <eagle@eyrie.org>
9 * The authors hereby relinquish any claim to any copyright that they may have
10 * in this work, whether granted under contract or by operation of law or
11 * international treaty, and hereby commit to the public, at large, that they
12 * shall not, at any time in the future, seek to enforce any copyright in this
13 * work against any person or entity, or prevent any person or entity from
14 * copying, publishing, distributing or creating derivative works of this
19 #include <portable/system.h>
23 #include <tests/tap/basic.h>
25 char *test_strndup(const char *, size_t);
36 result = test_strndup("foo", 8);
37 is_string("foo", result, "strndup longer than string");
39 result = test_strndup("foo", 2);
40 is_string("fo", result, "strndup shorter than string");
42 result = test_strndup("foo", 3);
43 is_string("foo", result, "strndup same size as string");
45 result = test_strndup("foo", 0);
46 is_string("", result, "strndup of size 0");
48 memcpy(buffer, "foo", 3);
49 result = test_strndup(buffer, 3);
50 is_string("foo", result, "strndup of non-nul-terminated string");
53 result = test_strndup(NULL, 0);
54 is_string(NULL, result, "strndup of NULL");
55 is_int(errno, EINVAL, "...and returns EINVAL");