glob: Declare variables at the very start of their scope.
[gnulib/ericb.git] / m4 / dup.m4
blob75307cbb89f557ca6d4c056073589decfbb93558
1 # dup.m4 serial 5
2 dnl Copyright (C) 2011-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_DUP],
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10   m4_ifdef([gl_MSVC_INVAL], [
11     AC_REQUIRE([gl_MSVC_INVAL])
12     if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
13       REPLACE_DUP=1
14     fi
15   ])
16   dnl Replace dup() for supporting the gnulib-defined fchdir() function,
17   dnl to keep fchdir's bookkeeping up-to-date.
18   m4_ifdef([gl_FUNC_FCHDIR], [
19     gl_TEST_FCHDIR
20     if test $HAVE_FCHDIR = 0; then
21       REPLACE_DUP=1
22     fi
23   ])
24   AC_CACHE_CHECK([whether dup works], [gl_cv_func_dup_works],
25     [AC_RUN_IFELSE(
26       [AC_LANG_PROGRAM([[#include <unistd.h>
27                          #include <fcntl.h>
28                          #include <errno.h>]],
29          [[/* On OS/2 kLIBC, dup does not work on a directory fd.  */
30            int fd = open (".", O_RDONLY);
31            return fd < 0 ? 1 : dup (fd) < 0 ? 2 : 0;
32          ]])
33       ],
34       [gl_cv_func_dup_works=yes],
35       [gl_cv_func_dup_works=no],
36       [gl_cv_func_dup_works='guessing yes'])
37     ])
38   case "$gl_cv_func_dup_works" in
39     *yes) ;;
40     *)
41       REPLACE_DUP=1
42       ;;
43   esac
46 # Prerequisites of lib/dup.c.
47 AC_DEFUN([gl_PREREQ_DUP], [:])