00001 /* Implement the stpncpy function. 00002 Copyright (C) 2003 Free Software Foundation, Inc. 00003 Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. 00004 00005 This file is part of the libiberty library. 00006 Libiberty is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 Libiberty is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with libiberty; see the file COPYING.LIB. If 00018 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. */ 00020 00021 /* 00022 00023 @deftypefn Supplemental char* stpncpy (char *@var{dst}, const char *@var{src}, size_t @var{len}) 00024 00025 Copies the string @var{src} into @var{dst}, copying exactly @var{len} 00026 and padding with zeros if necessary. If @var{len} < strlen(@var{src}) 00027 then return @var{dst} + @var{len}, otherwise returns @var{dst} + 00028 strlen(@var{src}). 00029 00030 @end deftypefn 00031 00032 */ 00033 00034 #include <ansidecl.h> 00035 #ifdef ANSI_PROTOTYPES 00036 #include <stddef.h> 00037 #else 00038 #define size_t unsigned long 00039 #endif 00040 00041 extern size_t strlen PARAMS ((const char *)); 00042 extern char *strncpy PARAMS ((char *, const char *, size_t)); 00043 00044 char * 00045 stpncpy (dst, src, len) 00046 char *dst; 00047 const char *src; 00048 size_t len; 00049 { 00050 size_t n = strlen (src); 00051 if (n > len) 00052 n = len; 00053 return strncpy (dst, src, len) + n; 00054 }
1.5.6