xref: /freebsd/contrib/ldns/m4/ax_have_poll.m4 (revision 02e9120893770924227138ba49df1edb3896112a)
1# ===========================================================================
2#       https://www.gnu.org/software/autoconf-archive/ax_have_poll.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_HAVE_POLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
8#   AX_HAVE_PPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
9#
10# DESCRIPTION
11#
12#   This macro determines whether the system supports the poll I/O event
13#   interface. A neat usage example would be:
14#
15#     AX_HAVE_POLL(
16#       [AX_CONFIG_FEATURE_ENABLE(poll)],
17#       [AX_CONFIG_FEATURE_DISABLE(poll)])
18#     AX_CONFIG_FEATURE(
19#       [poll], [This platform supports poll(7)],
20#       [HAVE_POLL], [This platform supports poll(7).])
21#
22#   Some systems -- most notably Linux kernel 2.6.16 and later -- also have
23#   the variant ppoll(). The availability of that function can be tested
24#   with the second macro. Generally speaking, it is safe to assume that
25#   AX_HAVE_POLL would succeed if AX_HAVE_PPOLL has, but not the other way
26#   round.
27#
28# LICENSE
29#
30#   Copyright (c) 2009 Peter Simons <simons@cryp.to>
31#
32#   Copying and distribution of this file, with or without modification, are
33#   permitted in any medium without royalty provided the copyright notice
34#   and this notice are preserved. This file is offered as-is, without any
35#   warranty.
36
37#serial 8
38
39AC_DEFUN([AX_HAVE_POLL], [dnl
40  AC_MSG_CHECKING([for poll(2)])
41  AC_CACHE_VAL([ax_cv_have_poll], [dnl
42    AC_LINK_IFELSE([dnl
43      AC_LANG_PROGRAM(
44        [#include <poll.h>],
45        [int rc; rc = poll((struct pollfd *)(0), 0, 0);])],
46      [ax_cv_have_poll=yes],
47      [ax_cv_have_poll=no])])
48  AS_IF([test "${ax_cv_have_poll}" = "yes"],
49    [AC_MSG_RESULT([yes])
50$1],[AC_MSG_RESULT([no])
51$2])
52])dnl
53
54AC_DEFUN([AX_HAVE_PPOLL], [dnl
55  AC_MSG_CHECKING([for ppoll(2)])
56  AC_CACHE_VAL([ax_cv_have_ppoll], [dnl
57    AC_LINK_IFELSE([dnl
58      AC_LANG_PROGRAM(
59        [dnl
60#include <poll.h>
61#include <signal.h>],
62        [dnl
63int rc;
64rc = poll((struct pollfd *)(0), 0, 0);
65rc = ppoll((struct pollfd *)(0), 0, (struct timespec const *)(0), (sigset_t const *)(0));])],
66      [ax_cv_have_ppoll=yes],
67      [ax_cv_have_ppoll=no])])
68  AS_IF([test "${ax_cv_have_ppoll}" = "yes"],
69    [AC_MSG_RESULT([yes])
70$1],[AC_MSG_RESULT([no])
71$2])
72])
73