12a6b7db3Sskrll /* Implement the stpncpy function.
2*f22f0ef4Schristos    Copyright (C) 2003-2022 Free Software Foundation, Inc.
32a6b7db3Sskrll    Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
42a6b7db3Sskrll 
52a6b7db3Sskrll This file is part of the libiberty library.
62a6b7db3Sskrll Libiberty is free software; you can redistribute it and/or
72a6b7db3Sskrll modify it under the terms of the GNU Library General Public
82a6b7db3Sskrll License as published by the Free Software Foundation; either
92a6b7db3Sskrll version 2 of the License, or (at your option) any later version.
102a6b7db3Sskrll 
112a6b7db3Sskrll Libiberty is distributed in the hope that it will be useful,
122a6b7db3Sskrll but WITHOUT ANY WARRANTY; without even the implied warranty of
132a6b7db3Sskrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
142a6b7db3Sskrll Library General Public License for more details.
152a6b7db3Sskrll 
162a6b7db3Sskrll You should have received a copy of the GNU Library General Public
172a6b7db3Sskrll License along with libiberty; see the file COPYING.LIB.  If
182a6b7db3Sskrll not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
192a6b7db3Sskrll Boston, MA 02110-1301, USA.  */
202a6b7db3Sskrll 
212a6b7db3Sskrll /*
222a6b7db3Sskrll 
2305caefcfSchristos @deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, @
2405caefcfSchristos   size_t @var{len})
252a6b7db3Sskrll 
262a6b7db3Sskrll Copies the string @var{src} into @var{dst}, copying exactly @var{len}
272a6b7db3Sskrll and padding with zeros if necessary.  If @var{len} < strlen(@var{src})
282a6b7db3Sskrll then return @var{dst} + @var{len}, otherwise returns @var{dst} +
292a6b7db3Sskrll strlen(@var{src}).
302a6b7db3Sskrll 
312a6b7db3Sskrll @end deftypefn
322a6b7db3Sskrll 
332a6b7db3Sskrll */
342a6b7db3Sskrll 
352a6b7db3Sskrll #include <ansidecl.h>
362a6b7db3Sskrll #include <stddef.h>
372a6b7db3Sskrll 
382a6b7db3Sskrll extern size_t strlen (const char *);
392a6b7db3Sskrll extern char *strncpy (char *, const char *, size_t);
402a6b7db3Sskrll 
412a6b7db3Sskrll char *
stpncpy(char * dst,const char * src,size_t len)422a6b7db3Sskrll stpncpy (char *dst, const char *src, size_t len)
432a6b7db3Sskrll {
442a6b7db3Sskrll   size_t n = strlen (src);
452a6b7db3Sskrll   if (n > len)
462a6b7db3Sskrll     n = len;
472a6b7db3Sskrll   return strncpy (dst, src, len) + n;
482a6b7db3Sskrll }
49