X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fstrndup.c;h=88c3332e8191e25071de4368f29a899472ad6a26;hb=b4a983cb93fa80d1653194e0a58231327c7d8cd3;hp=3d6b93d3143574f2e680ccf53f207003e721a39f;hpb=0fad4bdb8e54f631e012ec382b6e337e7c897502;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/strndup.c b/libiberty/strndup.c index 3d6b93d314..88c3332e81 100644 --- a/libiberty/strndup.c +++ b/libiberty/strndup.c @@ -1,5 +1,5 @@ /* Implement the strndup function. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005-2019 Free Software Foundation, Inc. Written by Kaveh R. Ghazi . This file is part of the libiberty library. @@ -15,8 +15,8 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ /* @@ -31,31 +31,22 @@ memory was available. The result is always NUL terminated. */ #include "ansidecl.h" -#ifdef ANSI_PROTOTYPES #include -#else -#define size_t unsigned long -#endif -extern size_t strlen PARAMS ((const char*)); -extern PTR malloc PARAMS ((size_t)); -extern PTR memcpy PARAMS ((PTR, const PTR, size_t)); +extern size_t strnlen (const char *s, size_t maxlen); +extern PTR malloc (size_t); +extern PTR memcpy (PTR, const PTR, size_t); char * -strndup(s, n) - const char *s; - size_t n; +strndup (const char *s, size_t n) { char *result; - size_t len = strlen (s); + size_t len = strnlen (s, n); - if (n < len) - len = n; - - result = malloc (len + 1); + result = (char *) malloc (len + 1); if (!result) return 0; result[len] = '\0'; - return memcpy (result, s, len); + return (char *) memcpy (result, s, len); }