aboutsummaryrefslogtreecommitdiff
path: root/libiberty/strndup.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-01-04 23:47:07 +1030
committerAlan Modra <amodra@gmail.com>2017-01-05 00:03:07 +1030
commite495212d229d58eb4d70c94d7f828a04c386c3b2 (patch)
tree0c2f7c89f1388662be01e6692aec212517e7c699 /libiberty/strndup.c
parent0913ae5ad7ad465e36784ed7fcc8676f3e0e23b7 (diff)
downloadgdb-e495212d229d58eb4d70c94d7f828a04c386c3b2.zip
gdb-e495212d229d58eb4d70c94d7f828a04c386c3b2.tar.gz
gdb-e495212d229d58eb4d70c94d7f828a04c386c3b2.tar.bz2
Sync libiberty from gcc
Picks up copyright year update and other recent fixes.
Diffstat (limited to 'libiberty/strndup.c')
-rw-r--r--libiberty/strndup.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/libiberty/strndup.c b/libiberty/strndup.c
index 9e9b4e2..0a4cda4 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-2017 Free Software Foundation, Inc.
Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
This file is part of the libiberty library.
@@ -33,7 +33,7 @@ memory was available. The result is always NUL terminated.
#include "ansidecl.h"
#include <stddef.h>
-extern size_t strlen (const char*);
+extern size_t strnlen (const char *s, size_t maxlen);
extern PTR malloc (size_t);
extern PTR memcpy (PTR, const PTR, size_t);
@@ -41,10 +41,7 @@ char *
strndup (const char *s, size_t n)
{
char *result;
- size_t len = strlen (s);
-
- if (n < len)
- len = n;
+ size_t len = strnlen (s, n);
result = (char *) malloc (len + 1);
if (!result)