+2006-09-27 Jim Meyering <jim@meyering.net>
+
+ This function could end up with a definition for a function
+ named __strndup, rather than rpl_strndup on a system with
+ incomplete weak_alias support.
+ * strndup.c (strndup): Rename from __strndup.
+ Remove #defines that used to map __strndup to strndup.
+ Don't use K&R prototypes.
+ Remove LIBC-related code, since this file is not sync'd with glibc.
+ * strndup.h: Revamp, accordingly.
+
2006-09-27 Paul Eggert <eggert@cs.ucla.edu>
* canon-host.c (canon_host_r): Work around bug in Darwin 7.9.0
-/* Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 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, 1997, 1998, 2001, 2002, 2003, 2005, 2006 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
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-#if !_LIBC
-# include <config.h>
-# include "strndup.h"
-#endif
+#include <config.h>
+#include "strndup.h"
#include <stdlib.h>
#include <string.h>
-#if !_LIBC
-# include "strnlen.h"
-# ifndef __strnlen
-# define __strnlen strnlen
-# endif
-#endif
-
-#undef __strndup
-#if _LIBC
-# undef strndup
-#endif
-
-#ifndef weak_alias
-# define __strndup strndup
-#endif
+#include "strnlen.h"
char *
-__strndup (s, n)
- const char *s;
- size_t n;
+strndup (char const *s, size_t n)
{
- size_t len = __strnlen (s, n);
+ size_t len = strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
new[len] = '\0';
return memcpy (new, s, len);
}
-#ifdef libc_hidden_def
-libc_hidden_def (__strndup)
-#endif
-#ifdef weak_alias
-weak_alias (__strndup, strndup)
-#endif
/* Duplicate a size-bounded string.
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006 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
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-#if HAVE_STRNDUP
-
-/* Get strndup() declaration. */
#include <string.h>
-
-#else
-
#include <stddef.h>
+#ifdef __STRNDUP_PREFIX
+# define _GL_CONCAT(x, y) x ## y
+# define _GL_XCONCAT(x, y) _GL_CONCAT (x, y)
+# define __STRNDUP_ID(y) _GL_XCONCAT (__STRNDUP_PREFIX, y)
+# undef strndup
+# define strndup __STRNDUP_ID (strndup)
+# if !HAVE_DECL_STRNDUP
/* Return a newly allocated copy of at most N bytes of STRING. */
extern char *strndup (const char *string, size_t n);
-
+# endif
#endif
+2006-09-27 Jim Meyering <jim@meyering.net>
+
+ * strndup.m4: Modernize.
+
2006-09-27 Paul Eggert <eggert@cs.ucla.edu>
* fpending.m4 (gl_FUNC_FPENDING): Check for stdio_ext at most once.
-# strndup.m4 serial 9
+# strndup.m4 serial 10
dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_DEFINE([HAVE_STRNDUP], 1,
[Define if you have the strndup() function and it works.])
else
+ AC_DEFINE([__STRNDUP_PREFIX], [[rpl_]],
+ [Define to rpl_ if the strndup replacement function should be used.])
AC_LIBOBJ([strndup])
- AC_DEFINE(strndup, rpl_strndup,
- [Define to rpl_strndup if the replacement function should be used,])
gl_PREREQ_STRNDUP
fi
])