Remove "fix" call for "long long" from ARI
[deliverable/binutils-gdb.git] / libiberty / strndup.c
index 3d6b93d3143574f2e680ccf53f207003e721a39f..88c3332e8191e25071de4368f29a899472ad6a26 100644 (file)
@@ -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 <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.  */
 
 /*
 
@@ -31,31 +31,22 @@ memory was available.  The result is always NUL terminated.
 */
 
 #include "ansidecl.h"
-#ifdef ANSI_PROTOTYPES
 #include <stddef.h>
-#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);
 }
This page took 0.050308 seconds and 4 git commands to generate.