Mercurial > hg > octave-nkf > gnulib-hg
changeset 4743:7aaa40d3d5f3
Test for stpncpy function.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 26 Sep 2003 14:28:10 +0000 |
parents | 8cdceb02d97e |
children | 78dd4a46e8e8 |
files | tests/test-stpncpy.c |
diffstat | 1 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/tests/test-stpncpy.c @@ -0,0 +1,41 @@ +/* Test the system defined function stpncpy(). */ + +#include <string.h> +#include <stdio.h> + +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; +}