1# sys_ioctl_h.m4 serial 12
2dnl Copyright (C) 2008-2020 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
7dnl Written by Bruno Haible.
8
9AC_DEFUN([gl_SYS_IOCTL_H],
10[
11  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
12  dnl once only, before all statements that occur in other macros.
13  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
14
15  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
16  if test $ac_cv_header_sys_ioctl_h = yes; then
17    HAVE_SYS_IOCTL_H=1
18    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
19    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
20    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
21      [gl_cv_decl_ioctl_in_sys_ioctl_h],
22      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
23       AC_COMPILE_IFELSE(
24         [AC_LANG_PROGRAM(
25            [[#include <sys/ioctl.h>]],
26            [[(void) ioctl;]])],
27         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
28         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
29      ])
30  else
31    HAVE_SYS_IOCTL_H=0
32  fi
33  AC_SUBST([HAVE_SYS_IOCTL_H])
34  dnl <sys/ioctl.h> is always overridden, because of GNULIB_POSIXCHECK.
35  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
36
37  dnl Check for declarations of anything we want to poison if the
38  dnl corresponding gnulib module is not in use.
39  gl_WARN_ON_USE_PREPARE([[#include <sys/ioctl.h>
40/* Some platforms declare ioctl in the wrong header.  */
41#if !(defined __GLIBC__ && !defined __UCLIBC__)
42# include <unistd.h>
43#endif
44    ]], [ioctl])
45])
46
47AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
48[
49  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
50  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
51  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
52  dnl Define it also as a C macro, for the benefit of the unit tests.
53  gl_MODULE_INDICATOR_FOR_TESTS([$1])
54])
55
56AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
57[
58  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
59  dnl Assume proper GNU behavior unless another module says otherwise.
60  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
61  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
62                        AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
63  REPLACE_IOCTL=0;      AC_SUBST([REPLACE_IOCTL])
64])
65