| 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. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_DUP], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 13 |
m4_ifdef([gl_MSVC_INVAL], [ |
| 14 |
AC_REQUIRE([gl_MSVC_INVAL]) |
| 15 |
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then |
| 16 |
REPLACE_DUP=1 |
| 17 |
fi |
| 18 |
]) |
| 19 |
dnl Replace dup() for supporting the gnulib-defined fchdir() function, |
| 20 |
dnl to keep fchdir's bookkeeping up-to-date. |
| 21 |
m4_ifdef([gl_FUNC_FCHDIR], [ |
| 22 |
gl_TEST_FCHDIR |
| 23 |
if test $HAVE_FCHDIR = 0; then |
| 24 |
REPLACE_DUP=1 |
| 25 |
fi |
| 26 |
]) |
| 27 |
AC_CACHE_CHECK([whether dup works], [gl_cv_func_dup_works], |
| 28 |
[AC_RUN_IFELSE( |
| 29 |
[AC_LANG_PROGRAM([[#include <unistd.h> |
| 30 |
#include <fcntl.h> |
| 31 |
#include <errno.h> |
| 32 |
]GL_MDA_DEFINES], |
| 33 |
[[/* On OS/2 kLIBC, dup does not work on a directory fd. */ |
| 34 |
int fd = open (".", O_RDONLY); |
| 35 |
return fd < 0 ? 1 : dup (fd) < 0 ? 2 : 0; |
| 36 |
]]) |
| 37 |
], |
| 38 |
[gl_cv_func_dup_works=yes], |
| 39 |
[gl_cv_func_dup_works=no], |
| 40 |
[case "$host_os" in |
| 41 |
# Guess no on native Windows. |
| 42 |
mingw* | windows*) gl_cv_func_dup_works="guessing no" ;; |
| 43 |
*) gl_cv_func_dup_works="guessing yes" ;; |
| 44 |
esac |
| 45 |
]) |
| 46 |
]) |
| 47 |
case "$gl_cv_func_dup_works" in |
| 48 |
*yes) ;; |
| 49 |
*) |
| 50 |
REPLACE_DUP=1 |
| 51 |
;; |
| 52 |
esac |
| 53 |
]) |
| 54 |
|
| 55 |
# Prerequisites of lib/dup.c. |
| 56 |
AC_DEFUN([gl_PREREQ_DUP], [:]) |