]> sourceware.org Git - glibc.git/blobdiff - string/strndup.c
stdlib: Avoid undefined behavior in stdlib/tst-labs
[glibc.git] / string / strndup.c
index 1e17925689fc9c64b6b9acf8d261584c5e09bc31..f0c9699d37c2c3de9c248e97ff890594a493b118 100644 (file)
@@ -1,20 +1,19 @@
-/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2023 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -38,12 +37,10 @@ char *malloc ();
 #endif
 
 char *
-__strndup (s, n)
-     const char *s;
-     size_t n;
+__strndup (const char *s, size_t n)
 {
-  size_t len = strnlen (s, n);
-  char *new = malloc (len + 1);
+  size_t len = __strnlen (s, n);
+  char *new = (char *) malloc (len + 1);
 
   if (new == NULL)
     return NULL;
@@ -51,6 +48,9 @@ __strndup (s, n)
   new[len] = '\0';
   return (char *) memcpy (new, s, len);
 }
+#ifdef libc_hidden_def
+libc_hidden_def (__strndup)
+#endif
 #ifdef weak_alias
 weak_alias (__strndup, strndup)
 #endif
This page took 0.028662 seconds and 5 git commands to generate.