root/maint/gnulib/tests/test-stpncpy.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test the system defined function stpncpy().
   2    Copyright (C) 2003, 2008-2021 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 <https://www.gnu.org/licenses/>.  */
  16 
  17 #include <config.h>
  18 
  19 #include <string.h>
  20 
  21 #include "signature.h"
  22 SIGNATURE_CHECK (stpncpy, char *, (char *, char const *, size_t));
  23 
  24 #include <stdio.h>
  25 
  26 int
  27 main ()
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29   char from[10];
  30   char to[10];
  31   int i, j, k, h;
  32   char *ret;
  33 
  34   for (i = 0; i < 10; i++)
  35     for (j = 0; j < 10; j++)
  36       for (k = 0; k < 10; k++)
  37         {
  38           memset (from, 'X', sizeof from);
  39           memcpy (from, "SourceString", i);
  40           if (i < 10) from[i] = '\0';
  41           memset (to, 'Y', sizeof to);
  42           memcpy (to, "Destination", k);
  43           if (k < 10) to[k] = '\0';
  44           ret = stpncpy (to, from, j);
  45           printf ("i = %2d, j = %2d, k = %2d:  from = ", i, j, k);
  46           for (h = 0; h < 10; h++)
  47             if (from[h] >= 0x20 && from[h] < 0x7f)
  48               putchar (from[h]);
  49             else
  50               printf ("\\x%02x", from[h]);
  51           printf ("  to = ");
  52           for (h = 0; h < 10; h++)
  53             if (to[h] >= 0x20 && to[h] < 0x7f)
  54               putchar (to[h]);
  55             else
  56               printf ("\\x%02x", to[h]);
  57           printf ("  ret = to + %d\n", ret - to);
  58         }
  59 
  60   return 0;
  61 }

/* [previous][next][first][last][top][bottom][index][help] */