2 dnl Copyright (C) 2002-2003, 2005 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 AC_DEFUN([gl_FUNC_STPNCPY],
11 dnl Persuade glibc <string.h> to declare stpncpy().
12 AC_REQUIRE([AC_GNU_SOURCE])
14 dnl Both glibc and AIX (4.3.3, 5.1) have an stpncpy() function
15 dnl declared in <string.h>. Its side effects are the same as those
17 dnl stpncpy (dest, src, n)
18 dnl overwrites dest[0..n-1], min(strlen(src),n) bytes coming from src,
19 dnl and the remaining bytes being NULs. However, the return value is
20 dnl in glibc: dest + min(strlen(src),n)
21 dnl in AIX: dest + max(0,n-1)
22 dnl Only the glibc return value is useful in practice.
24 AC_CACHE_CHECK([for working stpncpy], gl_cv_func_stpncpy, [
27 extern char *stpncpy (char *dest, const char *src, size_t n);
29 const char *src = "Hello";
31 /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+1 here. */
32 strcpy (dest, "\377\377\377\377\377\377");
33 if (stpncpy (dest, src, 2) != dest + 2) exit(1);
34 /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+4 here. */
35 strcpy (dest, "\377\377\377\377\377\377");
36 if (stpncpy (dest, src, 5) != dest + 5) exit(1);
37 /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+6 here. */
38 strcpy (dest, "\377\377\377\377\377\377");
39 if (stpncpy (dest, src, 7) != dest + 5) exit(1);
42 ], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no,
43 [AC_EGREP_CPP([Thanks for using GNU], [
45 #ifdef __GNU_LIBRARY__
48 ], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no)])])
50 if test $gl_cv_func_stpncpy = yes; then
51 AC_DEFINE(HAVE_STPNCPY, 1,
52 [Define if you have the stpncpy() function and it works.])
54 AC_DEFINE([stpncpy], [gnu_stpncpy],
55 [Define to a replacement function name for stpncpy().])
61 # Prerequisites of lib/stpncpy.c.
62 AC_DEFUN([gl_PREREQ_STPNCPY], [