Include config.h in all tests.
[gnulib.git] / tests / test-stpncpy.c
1 /* Test the system defined function stpncpy().
2    Copyright (C) 2003, 2008 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 #include <config.h>
18
19 #include <string.h>
20 #include <stdio.h>
21
22 int
23 main ()
24 {
25   char from[10];
26   char to[10];
27   int i, j, k, h;
28   char *ret;
29
30   for (i = 0; i < 10; i++)
31     for (j = 0; j < 10; j++)
32       for (k = 0; k < 10; k++)
33         {
34           memset (from, 'X', sizeof from);
35           memcpy (from, "SourceString", i);
36           if (i < 10) from[i] = '\0';
37           memset (to, 'Y', sizeof to);
38           memcpy (to, "Destination", k);
39           if (k < 10) to[k] = '\0';
40           ret = stpncpy (to, from, j);
41           printf ("i = %2d, j = %2d, k = %2d:  from = ", i, j, k);
42           for (h = 0; h < 10; h++)
43             if (from[h] >= 0x20 && from[h] < 0x7f)
44               putchar (from[h]);
45             else
46               printf ("\\x%02x", from[h]);
47           printf ("  to = ");
48           for (h = 0; h < 10; h++)
49             if (to[h] >= 0x20 && to[h] < 0x7f)
50               putchar (to[h]);
51             else
52               printf ("\\x%02x", to[h]);
53           printf ("  ret = to + %d\n", ret - to);
54         }
55
56   return 0;
57 }