174462Salfred/* Implement the stpncpy function. 274462Salfred Copyright (C) 2003, 2011 Free Software Foundation, Inc. 374462Salfred Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. 474462Salfred 574462SalfredThis file is part of the libiberty library. 674462SalfredLibiberty is free software; you can redistribute it and/or 774462Salfredmodify it under the terms of the GNU Library General Public 874462SalfredLicense as published by the Free Software Foundation; either 974462Salfredversion 2 of the License, or (at your option) any later version. 1074462Salfred 1174462SalfredLibiberty is distributed in the hope that it will be useful, 1274462Salfredbut WITHOUT ANY WARRANTY; without even the implied warranty of 1374462SalfredMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1474462SalfredLibrary General Public License for more details. 1574462Salfred 1674462SalfredYou should have received a copy of the GNU Library General Public 1774462SalfredLicense along with libiberty; see the file COPYING.LIB. If 1874462Salfrednot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 1974462SalfredBoston, MA 02110-1301, USA. */ 2074462Salfred 2174462Salfred/* 2274462Salfred 2374462Salfred@deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, @ 2474462Salfred size_t @var{len}) 2574462Salfred 2674462SalfredCopies the string @var{src} into @var{dst}, copying exactly @var{len} 2774462Salfredand padding with zeros if necessary. If @var{len} < strlen(@var{src}) 2874462Salfredthen return @var{dst} + @var{len}, otherwise returns @var{dst} + 2974462Salfredstrlen(@var{src}). 3074462Salfred 3174462Salfred@end deftypefn 3274462Salfred 3374462Salfred*/ 3474462Salfred 3574462Salfred#include <ansidecl.h> 3674462Salfred#include <stddef.h> 3774462Salfred 3874462Salfredextern size_t strlen (const char *); 3974462Salfredextern char *strncpy (char *, const char *, size_t); 4074462Salfred 4174462Salfredchar * 4274462Salfredstpncpy (char *dst, const char *src, size_t len) 4374462Salfred{ 4474462Salfred size_t n = strlen (src); 4574462Salfred if (n > len) 4674462Salfred n = len; 4774462Salfred return strncpy (dst, src, len) + n; 4874462Salfred} 4974462Salfred