doc: Add documentation about math_errhandling.
[gnulib.git] / m4 / dup.m4
blobb3d74d6850bd59eed775751d280e0b63fc70c1ac
1 # dup.m4
2 # serial 8
3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_DUP],
10   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   m4_ifdef([gl_MSVC_INVAL], [
13     AC_REQUIRE([gl_MSVC_INVAL])
14     if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
15       REPLACE_DUP=1
16     fi
17   ])
18   dnl Replace dup() for supporting the gnulib-defined fchdir() function,
19   dnl to keep fchdir's bookkeeping up-to-date.
20   m4_ifdef([gl_FUNC_FCHDIR], [
21     gl_TEST_FCHDIR
22     if test $HAVE_FCHDIR = 0; then
23       REPLACE_DUP=1
24     fi
25   ])
26   AC_CACHE_CHECK([whether dup works], [gl_cv_func_dup_works],
27     [AC_RUN_IFELSE(
28       [AC_LANG_PROGRAM([[#include <unistd.h>
29                          #include <fcntl.h>
30                          #include <errno.h>
31                        ]GL_MDA_DEFINES],
32          [[/* On OS/2 kLIBC, dup does not work on a directory fd.  */
33            int fd = open (".", O_RDONLY);
34            return fd < 0 ? 1 : dup (fd) < 0 ? 2 : 0;
35          ]])
36       ],
37       [gl_cv_func_dup_works=yes],
38       [gl_cv_func_dup_works=no],
39       [case "$host_os" in
40                             # Guess no on native Windows.
41          mingw* | windows*) gl_cv_func_dup_works="guessing no" ;;
42          *)                 gl_cv_func_dup_works="guessing yes" ;;
43        esac
44       ])
45     ])
46   case "$gl_cv_func_dup_works" in
47     *yes) ;;
48     *)
49       REPLACE_DUP=1
50       ;;
51   esac
54 # Prerequisites of lib/dup.c.
55 AC_DEFUN([gl_PREREQ_DUP], [:])