From fb4fb5428d50d3d0c092a60f5ef4410f250ed2c4 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 3 Nov 2001 09:05:11 +0000 Subject: Update. 2001-11-02 Jakub Jelinek * string/bits/string2.h (__strndup): If n is smaller than len, set len to n + 1. * string/tester.c (test_strndup): New function. (main): Call it. * sunrpc/rpc_main.c: Optimize variable definitions a bit. --- string/tester.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'string/tester.c') diff --git a/string/tester.c b/string/tester.c index bd2445f0d1..39ae0d837e 100644 --- a/string/tester.c +++ b/string/tester.c @@ -1256,6 +1256,30 @@ test_bzero (void) equal(one, "abcdef", 4); /* Zero-length copy. */ } +static void +test_strndup (void) +{ + char *p, *q; + it = "strndup"; + p = strndup("abcdef", 12); + check(p != NULL, 1); + if (p != NULL) + { + equal(p, "abcdef", 2); + q = strndup(p + 1, 2); + check(q != NULL, 3); + if (q != NULL) + equal(q, "bc", 4); + free (q); + } + free (p); + p = strndup("abc def", 3); + check(p != NULL, 5); + if (p != NULL) + equal(p, "abc", 6); + free (p); +} + static void test_bcmp (void) { @@ -1382,6 +1406,9 @@ main (void) /* bcmp - somewhat like memcmp. */ test_bcmp (); + /* strndup. */ + test_strndup (); + /* strerror - VERY system-dependent. */ test_strerror (); -- cgit v1.2.3