strchrnul: work around cygwin bug
[gnulib.git] / m4 / strchrnul.m4
1 # strchrnul.m4 serial 8
2 dnl Copyright (C) 2003, 2007, 2009-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_STRCHRNUL],
8 [
9   dnl Persuade glibc <string.h> to declare strchrnul().
10   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11
12   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
13   AC_REPLACE_FUNCS([strchrnul])
14   if test $ac_cv_func_strchrnul = no; then
15     HAVE_STRCHRNUL=0
16     gl_PREREQ_STRCHRNUL
17   else
18     AC_CACHE_CHECK([whether strchrnul works],
19       [gl_cv_func_strchrnul_works],
20       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
21 #include <string.h> /* for strchrnul */
22 ]], [[const char *buf = "a";
23       return strchrnul(buf, 'b') != buf + 1;
24     ]])],
25         [gl_cv_func_strchrnul_works=yes],
26         [gl_cv_func_strchrnul_works=no],
27         [dnl Cygwin 1.7.9 introduced strchrnul, but it was broken until 1.7.10
28          AC_EGREP_CPP([Lucky user],
29            [
30 #if defined __CYGWIN__
31  #include <cygwin/version.h>
32  #if CYGWIN_VERSION_DLL_COMBINED > CYGWIN_VERSION_DLL_MAKE_COMBINED (1007, 9)
33   Lucky user
34  #endif
35 #else
36   Lucky user
37 #endif
38            ],
39            [gl_cv_func_strchrnul_works=yes],
40            [gl_cv_func_strchrnul_works="guessing no"])
41         ])
42       ])
43     if test "$gl_cv_func_strchrnul_works" != yes; then
44       REPLACE_STRCHRNUL=1
45       AC_LIBOBJ([strchrnul])
46     fi
47   fi
48 ])
49
50 # Prerequisites of lib/strchrnul.c.
51 AC_DEFUN([gl_PREREQ_STRCHRNUL], [:])