768cced0270728269eb04510cdd5eca973a1eb8c
[gnulib.git] / m4 / stpncpy.m4
1 # stpncpy.m4 serial 1
2 dnl Copyright (C) 2002-2003 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.
8
9 AC_DEFUN([gl_FUNC_STPNCPY],
10 [
11   dnl Persuade glibc <string.h> to declare stpncpy().
12   AC_REQUIRE([AC_GNU_SOURCE])
13
14   AC_CACHE_CHECK([for working stpncpy], gl_cv_func_stpncpy, [
15     AC_TRY_RUN([
16 #include <stdlib.h>
17 extern char *stpncpy (char *dest, const char *src, size_t n);
18 int main () {
19   const char *src = "Hello";
20   char dest[10];
21   /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+1 here.  */
22   strcpy (dest, "\377\377\377\377\377\377");
23   if (stpncpy (dest, src, 2) != dest + 2) exit(1);
24   /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+4 here.  */
25   strcpy (dest, "\377\377\377\377\377\377");
26   if (stpncpy (dest, src, 5) != dest + 5) exit(1);
27   /* AIX 4.3.3 and AIX 5.1 stpncpy() returns dest+6 here.  */
28   strcpy (dest, "\377\377\377\377\377\377");
29   if (stpncpy (dest, src, 7) != dest + 5) exit(1);
30   exit(0);
31 }
32 ], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no,
33   [AC_EGREP_CPP([Thanks for using GNU], [
34 #include <features.h>
35 #ifdef __GNU_LIBRARY__
36   Thanks for using GNU
37 #endif
38 ], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no)])])
39
40   if test $gl_cv_func_stpncpy = yes; then
41     AC_DEFINE(HAVE_STPNCPY, 1,
42       [Define if you have the stpncpy() function and it works.])
43   else
44     AC_LIBOBJ([stpncpy])
45     AC_DEFINE(stpncpy, rpl_stpncpy,
46       [Define to rpl_stpncpy if the replacement function should be used.])
47     gl_PREREQ_STPNCPY
48   fi
49 ])
50
51 # Prerequisites of lib/stpncpy.c.
52 AC_DEFUN([gl_PREREQ_STPNCPY], [
53   :
54 ])
55