-/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+/* A replacement function, for systems that lack strndup.
- NOTE: The canonical source of this file is maintained with the GNU C Library.
- Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+ Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <config.h>
-#include <stdio.h>
-#include <sys/types.h>
+#include <string.h>
-#if defined _LIBC || defined STDC_HEADERS
-# include <stdlib.h>
-# include <string.h>
-#else
-char *malloc ();
-#endif
-
-#undef __strndup
-#undef strndup
-
-#ifndef weak_alias
-# define __strndup strndup
-#endif
+#include <stdlib.h>
char *
-__strndup (const char *s, size_t n)
+strndup (char const *s, size_t n)
{
size_t len = strnlen (s, n);
char *new = malloc (len + 1);
return NULL;
new[len] = '\0';
- return (char *) memcpy (new, s, len);
+ return memcpy (new, s, len);
}
-#ifdef weak_alias
-weak_alias (__strndup, strndup)
-#endif