2015-02-24 16:38:16 -08:00
|
|
|
#serial 24
|
2015-01-01 11:05:24 -08:00
|
|
|
dnl Copyright (C) 2002, 2005, 2007, 2009-2015 Free Software Foundation, Inc.
|
2011-06-25 01:40:38 -07:00
|
|
|
dnl This file is free software; the Free Software Foundation
|
|
|
|
dnl gives unlimited permission to copy and/or distribute it,
|
|
|
|
dnl with or without modifications, as long as this notice is preserved.
|
|
|
|
|
|
|
|
AC_DEFUN([gl_FUNC_DUP2],
|
|
|
|
[
|
|
|
|
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
|
|
|
|
AC_REQUIRE([AC_CANONICAL_HOST])
|
|
|
|
m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
|
|
|
|
AC_CHECK_FUNCS_ONCE([dup2])
|
|
|
|
if test $ac_cv_func_dup2 = no; then
|
|
|
|
HAVE_DUP2=0
|
|
|
|
fi
|
|
|
|
], [
|
|
|
|
AC_DEFINE([HAVE_DUP2], [1], [Define to 1 if you have the 'dup2' function.])
|
|
|
|
])
|
|
|
|
if test $HAVE_DUP2 = 1; then
|
|
|
|
AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
|
|
|
|
[AC_RUN_IFELSE([
|
Merge from gnulib
* doc/misc/texinfo.tex: Update from gnulib.
* lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c:
* lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4:
Update from gnulib, incorporating:
2015-02-20 getdtablesize: port better for Android
2015-02-19 fcntl: Fix cross compiling
2015-02-18 dup2, fcntl: cross-compile better for Android
2015-02-18 getopt: don't crash on memory exhaustion
2015-02-17 tempname: allow compilation with C++ (trivial)
2015-02-17 dup2, fcntl: port to AIX
2015-02-16 getdtablesize, dup2, fcntl: port to Android
2015-02-11 getdtablesize, signal_h: Fix Android build
2015-02-11 maint: various whitespace cleanups in tempname
2015-02-20 23:31:17 -08:00
|
|
|
AC_LANG_PROGRAM(
|
|
|
|
[[#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2015-02-24 16:38:16 -08:00
|
|
|
#ifndef RLIM_SAVED_CUR
|
|
|
|
# define RLIM_SAVED_CUR RLIM_INFINITY
|
|
|
|
#endif
|
|
|
|
#ifndef RLIM_SAVED_MAX
|
|
|
|
# define RLIM_SAVED_MAX RLIM_INFINITY
|
|
|
|
#endif
|
Merge from gnulib
* doc/misc/texinfo.tex: Update from gnulib.
* lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c:
* lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4:
Update from gnulib, incorporating:
2015-02-20 getdtablesize: port better for Android
2015-02-19 fcntl: Fix cross compiling
2015-02-18 dup2, fcntl: cross-compile better for Android
2015-02-18 getopt: don't crash on memory exhaustion
2015-02-17 tempname: allow compilation with C++ (trivial)
2015-02-17 dup2, fcntl: port to AIX
2015-02-16 getdtablesize, dup2, fcntl: port to Android
2015-02-11 getdtablesize, signal_h: Fix Android build
2015-02-11 maint: various whitespace cleanups in tempname
2015-02-20 23:31:17 -08:00
|
|
|
]],
|
|
|
|
[[int result = 0;
|
|
|
|
int bad_fd = INT_MAX;
|
|
|
|
struct rlimit rlim;
|
|
|
|
if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
|
|
|
|
&& 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
|
|
|
|
&& rlim.rlim_cur != RLIM_INFINITY
|
|
|
|
&& rlim.rlim_cur != RLIM_SAVED_MAX
|
|
|
|
&& rlim.rlim_cur != RLIM_SAVED_CUR)
|
|
|
|
bad_fd = rlim.rlim_cur;
|
|
|
|
#ifdef FD_CLOEXEC
|
|
|
|
if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
|
|
|
|
result |= 1;
|
|
|
|
#endif
|
2015-02-24 16:38:16 -08:00
|
|
|
if (dup2 (1, 1) != 1)
|
Merge from gnulib
* doc/misc/texinfo.tex: Update from gnulib.
* lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c:
* lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4:
Update from gnulib, incorporating:
2015-02-20 getdtablesize: port better for Android
2015-02-19 fcntl: Fix cross compiling
2015-02-18 dup2, fcntl: cross-compile better for Android
2015-02-18 getopt: don't crash on memory exhaustion
2015-02-17 tempname: allow compilation with C++ (trivial)
2015-02-17 dup2, fcntl: port to AIX
2015-02-16 getdtablesize, dup2, fcntl: port to Android
2015-02-11 getdtablesize, signal_h: Fix Android build
2015-02-11 maint: various whitespace cleanups in tempname
2015-02-20 23:31:17 -08:00
|
|
|
result |= 2;
|
|
|
|
#ifdef FD_CLOEXEC
|
|
|
|
if (fcntl (1, F_GETFD) != FD_CLOEXEC)
|
|
|
|
result |= 4;
|
|
|
|
#endif
|
|
|
|
close (0);
|
|
|
|
if (dup2 (0, 0) != -1)
|
|
|
|
result |= 8;
|
|
|
|
/* Many gnulib modules require POSIX conformance of EBADF. */
|
|
|
|
if (dup2 (2, bad_fd) == -1 && errno != EBADF)
|
|
|
|
result |= 16;
|
|
|
|
/* Flush out some cygwin core dumps. */
|
|
|
|
if (dup2 (2, -1) != -1 || errno != EBADF)
|
|
|
|
result |= 32;
|
|
|
|
dup2 (2, 255);
|
|
|
|
dup2 (2, 256);
|
|
|
|
return result;]])
|
2011-06-25 01:40:38 -07:00
|
|
|
],
|
|
|
|
[gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
|
|
|
|
[case "$host_os" in
|
|
|
|
mingw*) # on this platform, dup2 always returns 0 for success
|
2012-05-26 16:14:36 -07:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2011-06-25 01:40:38 -07:00
|
|
|
cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
|
2012-05-26 16:14:36 -07:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2014-06-01 16:58:38 -07:00
|
|
|
aix* | freebsd*)
|
|
|
|
# on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
|
|
|
|
# not EBADF.
|
2012-05-26 16:14:36 -07:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2011-06-25 01:40:38 -07:00
|
|
|
haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
|
2012-05-26 16:14:36 -07:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2015-02-24 16:38:16 -08:00
|
|
|
*-android*) # implemented using dup3(), which fails if oldfd == newfd
|
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2012-05-26 16:14:36 -07:00
|
|
|
*) gl_cv_func_dup2_works="guessing yes" ;;
|
2011-06-25 01:40:38 -07:00
|
|
|
esac])
|
|
|
|
])
|
2012-05-26 16:14:36 -07:00
|
|
|
case "$gl_cv_func_dup2_works" in
|
|
|
|
*yes) ;;
|
|
|
|
*)
|
|
|
|
REPLACE_DUP2=1
|
2013-10-03 00:06:52 -07:00
|
|
|
AC_CHECK_FUNCS([setdtablesize])
|
2012-05-26 16:14:36 -07:00
|
|
|
;;
|
|
|
|
esac
|
2011-06-25 01:40:38 -07:00
|
|
|
fi
|
2011-07-28 09:35:19 -07:00
|
|
|
dnl Replace dup2() for supporting the gnulib-defined fchdir() function,
|
|
|
|
dnl to keep fchdir's bookkeeping up-to-date.
|
|
|
|
m4_ifdef([gl_FUNC_FCHDIR], [
|
|
|
|
gl_TEST_FCHDIR
|
|
|
|
if test $HAVE_FCHDIR = 0; then
|
2012-05-26 16:14:36 -07:00
|
|
|
if test $HAVE_DUP2 = 1; then
|
|
|
|
REPLACE_DUP2=1
|
|
|
|
fi
|
2011-07-28 09:35:19 -07:00
|
|
|
fi
|
|
|
|
])
|
2011-06-25 01:40:38 -07:00
|
|
|
])
|
Merge from gnulib, improving some licensing wording.
This clarifies and fixes some licensing issues raised by Glenn Morris
<http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00397.html>.
It also merges the latest version of texinfo.tex and has some
MSVC-related changes that don't affect Emacs.
* Makefile.in (GNULIB_TOOL_FLAGS): Avoid msvc-inval, msvc-nothrow,
pathmax, and raise, since these are needed only to address
MSVC-related issues that Emacs doesn't have.
* doc/misc/texinfo.tex, lib/dup2.c, lib/gnulib.mk, lib/signal.in.h:
* lib/sigprocmask.c, lib/stat.c, lib/stdio.in.h, lib/sys_stat.in.h:
* lib/unistd.in.h, m4/dup2.m4, m4/getloadavg.m4, m4/gl-comp.m4:
* m4/include_next.m4, m4/signal_h.m4, m4/signalblocking.m4:
* m4/stdint.m4, m4/stdio_h.m4, m4/sys_stat_h.m4, m4/time_h.m4:
* m4/unistd_h.m4: Merge from gnulib.
2011-09-26 14:30:18 -07:00
|
|
|
|
|
|
|
# Prerequisites of lib/dup2.c.
|
|
|
|
AC_DEFUN([gl_PREREQ_DUP2], [])
|