660d8caf1ed86b6a15f14346055ac25b0b3e9b47
[gnulib.git] / tests / test-stpncpy.c
1 /* Test the system defined function stpncpy().  */
2
3 #include <string.h>
4 #include <stdio.h>
5
6 int
7 main ()
8 {
9   char from[10];
10   char to[10];
11   int i, j, k, h;
12   char *ret;
13
14   for (i = 0; i < 10; i++)
15     for (j = 0; j < 10; j++)
16       for (k = 0; k < 10; k++)
17         {
18           memset (from, 'X', sizeof from);
19           memcpy (from, "SourceString", i);
20           if (i < 10) from[i] = '\0';
21           memset (to, 'Y', sizeof to);
22           memcpy (to, "Destination", k);
23           if (k < 10) to[k] = '\0';
24           ret = stpncpy (to, from, j);
25           printf ("i = %2d, j = %2d, k = %2d:  from = ", i, j, k);
26           for (h = 0; h < 10; h++)
27             if (from[h] >= 0x20 && from[h] < 0x7f)
28               putchar (from[h]);
29             else
30               printf ("\\x%02x", from[h]);
31           printf ("  to = ");
32           for (h = 0; h < 10; h++)
33             if (to[h] >= 0x20 && to[h] < 0x7f)
34               putchar (to[h]);
35             else
36               printf ("\\x%02x", to[h]);
37           printf ("  ret = to + %d\n", ret - to);
38         }
39
40   return 0;
41 }