diff libiberty/strndup.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents a06113de4d67
children 84e7813d76e9
line wrap: on
line diff
--- a/libiberty/strndup.c	Sun Aug 21 07:07:55 2011 +0900
+++ b/libiberty/strndup.c	Fri Oct 27 22:46:09 2017 +0900
@@ -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 @@
 #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 @@
 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)