+2003-09-26 Bruno Haible <bruno@clisp.org>
+
+ * stpncpy.h (gnu_stpncpy): New declaration.
+ (stpncpy): Define as alias for gnu_stpncpy.
+ * stpncpy.c [!_LIBC]: Define gnu_stpncpy, not stpncpy.
+
2003-09-26 Paul Eggert <eggert@twinsun.com>
* error.c (SIZE_MAX) [!defined SIZE_MAX]: Define.
/* Specification. */
#include "stpncpy.h"
+#if !HAVE_STPNCPY
+
+#ifndef _LIBC
+/* We cannot generally use the name 'stpncpy' since AIX 4 defines an unusable
+ variant of the function but we cannot use it. */
+# undef stpncpy
+# define stpncpy gnu_stpncpy
+#endif
+
#ifndef weak_alias
# define __stpncpy stpncpy
#endif
-/* Copy no more than N characters of SRC to DEST, returning the address of
- the terminating '\0' in DEST, if any, or else DEST + N. */
+/* Copy no more than N bytes of SRC to DST, returning a pointer past the
+ last non-NUL byte written into DST. */
char *
__stpncpy (char *dest, const char *src, size_t n)
{
#ifdef weak_alias
weak_alias (__stpncpy, stpncpy)
#endif
+
+#endif
#ifndef _STPNCPY_H
#define _STPNCPY_H
-#if HAVE_STPNCPY
-
-/* Get stpncpy() declaration. */
#include <string.h>
-#else
-
-#include <stddef.h>
+#if !HAVE_STPNCPY
-/* Copy no more than N characters of SRC to DST, returning the address of
- the last character written into DST. */
-extern char *stpncpy (char *dst, const char *src, size_t n);
+/* Copy no more than N bytes of SRC to DST, returning a pointer past the
+ last non-NUL byte written into DST. */
+/* When not using the GNU libc we use the stpncpy implementation we
+ provide here. */
+extern char *gnu_stpncpy (char *dst, const char *src, size_t n);
+#define stpncpy(Dst, Src, N) gnu_stpncpy (Dst, Src, N)
#endif
+2003-09-26 Bruno Haible <bruno@clisp.org>
+
+ * stpncpy.m4: Add comments about the AIX stpncpy().
+
2003-09-25 Simon Josefsson <jas@extundo.com>
Bruno Haible <bruno@clisp.org>
dnl Persuade glibc <string.h> to declare stpncpy().
AC_REQUIRE([AC_GNU_SOURCE])
+ dnl Both glibc and AIX (4.3.3, 5.1) have an stpncpy() function
+ dnl declared in <string.h>. Its side effects are the same as those
+ dnl of strncpy():
+ dnl stpncpy (dest, src, n)
+ dnl overwrites dest[0..n-1], min(strlen(src),n) bytes coming from src,
+ dnl and the remaining bytes being NULs. However, the return value is
+ dnl in glibc: dest + min(strlen(src),n)
+ dnl in AIX: dest + max(0,n-1)
+ dnl Only the glibc return value is useful in practice.
+
AC_CACHE_CHECK([for working stpncpy], gl_cv_func_stpncpy, [
AC_TRY_RUN([
#include <stdlib.h>