Make add_separate_debug_objfile static
[deliverable/binutils-gdb.git] / libiberty / xstrndup.c
index b481e4ad712ec37c9889c8a6ada5ac1b819486f7..bb0b512dce58ccd8c1f8c4ff163cba2b9212d37a 100644 (file)
@@ -1,5 +1,5 @@
 /* Implement the xstrndup function.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005-2019 Free Software Foundation, Inc.
    Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
 
 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.  */
 
 /*
 
@@ -45,18 +45,13 @@ always NUL terminated.
 #include "libiberty.h"
 
 char *
-xstrndup (s, n)
-     const char *s;
-     size_t n;
+xstrndup (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 = xmalloc (len + 1);
+  result = XNEWVEC (char, len + 1);
 
   result[len] = '\0';
-  return memcpy (result, s, len);
+  return (char *) memcpy (result, s, len);
 }
This page took 0.024443 seconds and 4 git commands to generate.