Test for stpncpy function.
authorBruno Haible <bruno@clisp.org>
Fri, 26 Sep 2003 14:28:10 +0000 (14:28 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 26 Sep 2003 14:28:10 +0000 (14:28 +0000)
tests/test-stpncpy.c [new file with mode: 0644]

diff --git a/tests/test-stpncpy.c b/tests/test-stpncpy.c
new file mode 100644 (file)
index 0000000..660d8ca
--- /dev/null
@@ -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;
+}