From: Bruno Haible Date: Fri, 26 Sep 2003 14:28:10 +0000 (+0000) Subject: Test for stpncpy function. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69962a30c2f1a1664aba1df88225fcc75e57ba9f;p=pspp Test for stpncpy function. --- diff --git a/tests/test-stpncpy.c b/tests/test-stpncpy.c new file mode 100644 index 0000000000..660d8caf1e --- /dev/null +++ b/tests/test-stpncpy.c @@ -0,0 +1,41 @@ +/* Test the system defined function stpncpy(). */ + +#include +#include + +int +main () +{ + char from[10]; + char to[10]; + int i, j, k, h; + char *ret; + + for (i = 0; i < 10; i++) + for (j = 0; j < 10; j++) + for (k = 0; k < 10; k++) + { + memset (from, 'X', sizeof from); + memcpy (from, "SourceString", i); + if (i < 10) from[i] = '\0'; + memset (to, 'Y', sizeof to); + memcpy (to, "Destination", k); + if (k < 10) to[k] = '\0'; + ret = stpncpy (to, from, j); + printf ("i = %2d, j = %2d, k = %2d: from = ", i, j, k); + for (h = 0; h < 10; h++) + if (from[h] >= 0x20 && from[h] < 0x7f) + putchar (from[h]); + else + printf ("\\x%02x", from[h]); + printf (" to = "); + for (h = 0; h < 10; h++) + if (to[h] >= 0x20 && to[h] < 0x7f) + putchar (to[h]); + else + printf ("\\x%02x", to[h]); + printf (" ret = to + %d\n", ret - to); + } + + return 0; +}