1169695Skan/* Implement the stpncpy function.
2169695Skan   Copyright (C) 2003 Free Software Foundation, Inc.
3169695Skan   Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
4169695Skan
5169695SkanThis file is part of the libiberty library.
6169695SkanLibiberty is free software; you can redistribute it and/or
7169695Skanmodify it under the terms of the GNU Library General Public
8169695SkanLicense as published by the Free Software Foundation; either
9169695Skanversion 2 of the License, or (at your option) any later version.
10169695Skan
11169695SkanLibiberty is distributed in the hope that it will be useful,
12169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
13169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14169695SkanLibrary General Public License for more details.
15169695Skan
16169695SkanYou should have received a copy of the GNU Library General Public
17169695SkanLicense along with libiberty; see the file COPYING.LIB.  If
18169695Skannot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19169695SkanBoston, MA 02110-1301, USA.  */
20169695Skan
21169695Skan/*
22169695Skan
23169695Skan@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, size_t @var{len})
24169695Skan
25169695SkanCopies the string @var{src} into @var{dst}, copying exactly @var{len}
26169695Skanand padding with zeros if necessary.  If @var{len} < strlen(@var{src})
27169695Skanthen return @var{dst} + @var{len}, otherwise returns @var{dst} +
28169695Skanstrlen(@var{src}).
29169695Skan
30169695Skan@end deftypefn
31169695Skan
32169695Skan*/
33169695Skan
34169695Skan#include <ansidecl.h>
35169695Skan#include <stddef.h>
36169695Skan
37169695Skanextern size_t strlen (const char *);
38169695Skanextern char *strncpy (char *, const char *, size_t);
39169695Skan
40169695Skanchar *
41169695Skanstpncpy (char *dst, const char *src, size_t len)
42169695Skan{
43169695Skan  size_t n = strlen (src);
44169695Skan  if (n > len)
45169695Skan    n = len;
46169695Skan  return strncpy (dst, src, len) + n;
47169695Skan}
48