xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/gnulib-m4/stpncpy.m4 (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1# stpncpy.m4 serial 4
2dnl Copyright (C) 2002-2003, 2005-2006 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_STPNCPY],
8[
9  dnl Persuade glibc <string.h> to declare stpncpy().
10  AC_REQUIRE([AC_GNU_SOURCE])
11
12  dnl Both glibc and AIX (4.3.3, 5.1) have an stpncpy() function
13  dnl declared in <string.h>. Its side effects are the same as those
14  dnl of strncpy():
15  dnl      stpncpy (dest, src, n)
16  dnl overwrites dest[0..n-1], min(strlen(src),n) bytes coming from src,
17  dnl and the remaining bytes being NULs.  However, the return value is
18  dnl   in glibc:   dest + min(strlen(src),n)
19  dnl   in AIX:     dest + max(0,n-1)
20  dnl Only the glibc return value is useful in practice.
21
22  AC_CACHE_CHECK([for working stpncpy], gl_cv_func_stpncpy, [
23    AC_TRY_RUN([
24#include <stdlib.h>
25#include <string.h> /* for strcpy */
26/* The stpncpy prototype is missing in <string.h> on AIX 4.  */
27extern char *stpncpy (char *dest, const char *src, size_t n);
28int main () {
29  const char *src = "Hello";
30  char dest[10];
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);
40  exit(0);
41}
42], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no,
43  [AC_EGREP_CPP([Thanks for using GNU], [
44#include <features.h>
45#ifdef __GNU_LIBRARY__
46  Thanks for using GNU
47#endif
48], gl_cv_func_stpncpy=yes, gl_cv_func_stpncpy=no)])])
49
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.])
53  else
54    AC_LIBOBJ([stpncpy])
55    gl_PREREQ_STPNCPY
56  fi
57])
58
59# Prerequisites of lib/stpncpy.c.
60AC_DEFUN([gl_PREREQ_STPNCPY], [
61  :
62])
63
64