glob.c: Silence warning about void pointer arithmetic
[gnulib.git] / m4 / ptsname_r.m4
blob362e1003a997648ef18db63a08173f6bb52a5705
1 # ptsname_r.m4 serial 4
2 dnl Copyright (C) 2010-2017 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.
7 AC_DEFUN([gl_FUNC_PTSNAME_R],
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   dnl Persuade glibc <stdlib.h> to declare ptsname_r().
12   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14   AC_CHECK_FUNCS_ONCE([ptsname_r])
15   if test $ac_cv_func_ptsname_r = no; then
16     HAVE_PTSNAME_R=0
17   else
18     dnl On OSF/1 5.1, the type of the third argument is 'int', not 'size_t',
19     dnl and the declaration is missing if _REENTRANT is not defined.
20     AC_CACHE_CHECK([whether ptsname_r has the same signature as in glibc],
21       [gl_cv_func_ptsname_r_signature_ok],
22       [AC_COMPILE_IFELSE(
23          [AC_LANG_PROGRAM(
24             [[#include <stddef.h>
25               #include <stdlib.h>
26               /* Test whether ptsname_r is declared at all.  */
27               int (*f) (int, char *, size_t) = ptsname_r;
28               /* Test whether it has the same declaration as in glibc.  */
29               #undef ptsname_r
30               extern
31               #ifdef __cplusplus
32               "C"
33               #endif
34               int ptsname_r (int, char *, size_t);
35             ]],
36             [[return f (0, NULL, 0);]])
37          ],
38          [gl_cv_func_ptsname_r_signature_ok=yes],
39          [gl_cv_func_ptsname_r_signature_ok=no])
40       ])
41     if test $gl_cv_func_ptsname_r_signature_ok = no; then
42       REPLACE_PTSNAME_R=1
43     fi
44   fi
46   AC_REQUIRE([AC_HEADER_MAJOR])
49 # Prerequisites of lib/ptsname.c.
50 AC_DEFUN([gl_PREREQ_PTSNAME_R], [
51   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
52   AC_CACHE_CHECK([whether isatty sets errno when it fails],
53     [gl_cv_func_isatty_sets_errno],
54     [AC_RUN_IFELSE(
55        [AC_LANG_PROGRAM(
56           [[#include <errno.h>
57             #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
58             # include <io.h>
59             #else
60             # include <unistd.h>
61             #endif
62           ]],
63           [[errno = 0;
64             isatty (-1);
65             return errno == 0;
66           ]])
67        ],
68        [gl_cv_func_isatty_sets_errno=yes],
69        [gl_cv_func_isatty_sets_errno=no],
70        [case "$host_os" in
71           irix* | solaris*)
72             gl_cv_func_isatty_sets_errno="guessing no" ;;
73           mingw*) # Guess yes on mingw, no on MSVC.
74             AC_EGREP_CPP([Known], [
75 #ifdef __MINGW32__
76  Known
77 #endif
78               ],
79               [gl_cv_func_isatty_sets_errno="guessing yes"],
80               [gl_cv_func_isatty_sets_errno="guessing no"])
81             ;;
82           *)
83             gl_cv_func_isatty_sets_errno="guessing yes" ;;
84         esac
85        ])
86     ])
87   case "$gl_cv_func_isatty_sets_errno" in
88     *yes) ;;
89     *)
90       AC_DEFINE([ISATTY_FAILS_WITHOUT_SETTING_ERRNO], [1],
91         [Define to 1 if isatty() may fail without setting errno.])
92       ;;
93   esac