Merge from gnulib
This incorporates:
2016-01-24 openat_proc_name: fix last '/' overwritten on OS/2 kLIBC
2016-01-24 closedir, dirfd, opendir: port to OpenSolaris 5.10
2016-01-15 detect utimes() correctly on OS/2 kLIBC
2016-01-15 openat_proc_name: port to OS/2 kLIBC
2016-01-14 stdint: check _INTPTR_T_DECLARED for intptr_t etc.
2016-01-14 opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
2016-01-14 dup, dup2, fcntl: support a directory fd on OS/2 kLIBC
2016-01-14 binary-io: don't put fd in binary mode if a console on EMX
2016-01-14 sig2str: list all signals on FreeBSD >= 7
2016-01-13 acl-permissions: port to USE_ACL==0 platforms
2016-01-12 mktime: rename macro to avoid glibc clash
2016-01-12 Port "$@" to OpenIndiana ksh93
2016-01-12 Port Universal Time settings to strict POSIX
* build-aux/gitlog-to-changelog, build-aux/update-copyright:
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/binary-io.h, lib/dirent.in.h, lib/dirfd.c, lib/dup2.c:
* lib/fcntl.c, lib/fdopendir.c, lib/mktime.c, lib/openat-proc.c:
* lib/sig2str.h, lib/stdint.in.h, m4/dirfd.m4, m4/dup2.m4:
* m4/fcntl.m4, m4/utimes.m4:
Copy from gnulib.
* m4/gnulib-comp.m4: Regenerate.
2016-01-24 22:50:47 +00:00
|
|
|
#serial 25
|
2017-01-01 09:32:27 +00:00
|
|
|
dnl Copyright (C) 2002, 2005, 2007, 2009-2017 Free Software Foundation, Inc.
|
2011-06-25 08:40:38 +00: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-21 07:31:17 +00:00
|
|
|
AC_LANG_PROGRAM(
|
|
|
|
[[#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2015-02-25 00:38:16 +00: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-21 07:31:17 +00: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-25 00:38:16 +00: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-21 07:31:17 +00: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);
|
Merge from gnulib
This incorporates:
2016-01-24 openat_proc_name: fix last '/' overwritten on OS/2 kLIBC
2016-01-24 closedir, dirfd, opendir: port to OpenSolaris 5.10
2016-01-15 detect utimes() correctly on OS/2 kLIBC
2016-01-15 openat_proc_name: port to OS/2 kLIBC
2016-01-14 stdint: check _INTPTR_T_DECLARED for intptr_t etc.
2016-01-14 opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
2016-01-14 dup, dup2, fcntl: support a directory fd on OS/2 kLIBC
2016-01-14 binary-io: don't put fd in binary mode if a console on EMX
2016-01-14 sig2str: list all signals on FreeBSD >= 7
2016-01-13 acl-permissions: port to USE_ACL==0 platforms
2016-01-12 mktime: rename macro to avoid glibc clash
2016-01-12 Port "$@" to OpenIndiana ksh93
2016-01-12 Port Universal Time settings to strict POSIX
* build-aux/gitlog-to-changelog, build-aux/update-copyright:
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/binary-io.h, lib/dirent.in.h, lib/dirfd.c, lib/dup2.c:
* lib/fcntl.c, lib/fdopendir.c, lib/mktime.c, lib/openat-proc.c:
* lib/sig2str.h, lib/stdint.in.h, m4/dirfd.m4, m4/dup2.m4:
* m4/fcntl.m4, m4/utimes.m4:
Copy from gnulib.
* m4/gnulib-comp.m4: Regenerate.
2016-01-24 22:50:47 +00:00
|
|
|
/* On OS/2 kLIBC, dup2() does not work on a directory fd. */
|
|
|
|
{
|
|
|
|
int fd = open (".", O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
result |= 64;
|
|
|
|
else if (dup2 (fd, fd + 1) == -1)
|
|
|
|
result |= 128;
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
}
|
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-21 07:31:17 +00:00
|
|
|
return result;]])
|
2011-06-25 08:40:38 +00: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 23:14:36 +00:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2011-06-25 08:40:38 +00:00
|
|
|
cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
|
2012-05-26 23:14:36 +00:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2014-06-01 23:58:38 +00:00
|
|
|
aix* | freebsd*)
|
|
|
|
# on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
|
|
|
|
# not EBADF.
|
2012-05-26 23:14:36 +00:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2011-06-25 08:40:38 +00:00
|
|
|
haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
|
2012-05-26 23:14:36 +00:00
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2015-02-25 00:38:16 +00:00
|
|
|
*-android*) # implemented using dup3(), which fails if oldfd == newfd
|
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
Merge from gnulib
This incorporates:
2016-01-24 openat_proc_name: fix last '/' overwritten on OS/2 kLIBC
2016-01-24 closedir, dirfd, opendir: port to OpenSolaris 5.10
2016-01-15 detect utimes() correctly on OS/2 kLIBC
2016-01-15 openat_proc_name: port to OS/2 kLIBC
2016-01-14 stdint: check _INTPTR_T_DECLARED for intptr_t etc.
2016-01-14 opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
2016-01-14 dup, dup2, fcntl: support a directory fd on OS/2 kLIBC
2016-01-14 binary-io: don't put fd in binary mode if a console on EMX
2016-01-14 sig2str: list all signals on FreeBSD >= 7
2016-01-13 acl-permissions: port to USE_ACL==0 platforms
2016-01-12 mktime: rename macro to avoid glibc clash
2016-01-12 Port "$@" to OpenIndiana ksh93
2016-01-12 Port Universal Time settings to strict POSIX
* build-aux/gitlog-to-changelog, build-aux/update-copyright:
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/binary-io.h, lib/dirent.in.h, lib/dirfd.c, lib/dup2.c:
* lib/fcntl.c, lib/fdopendir.c, lib/mktime.c, lib/openat-proc.c:
* lib/sig2str.h, lib/stdint.in.h, m4/dirfd.m4, m4/dup2.m4:
* m4/fcntl.m4, m4/utimes.m4:
Copy from gnulib.
* m4/gnulib-comp.m4: Regenerate.
2016-01-24 22:50:47 +00:00
|
|
|
os2*) # on OS/2 kLIBC, dup2() does not work on a directory fd.
|
|
|
|
gl_cv_func_dup2_works="guessing no" ;;
|
2012-05-26 23:14:36 +00:00
|
|
|
*) gl_cv_func_dup2_works="guessing yes" ;;
|
2011-06-25 08:40:38 +00:00
|
|
|
esac])
|
|
|
|
])
|
2012-05-26 23:14:36 +00:00
|
|
|
case "$gl_cv_func_dup2_works" in
|
|
|
|
*yes) ;;
|
|
|
|
*)
|
|
|
|
REPLACE_DUP2=1
|
2013-10-03 07:06:52 +00:00
|
|
|
AC_CHECK_FUNCS([setdtablesize])
|
2012-05-26 23:14:36 +00:00
|
|
|
;;
|
|
|
|
esac
|
2011-06-25 08:40:38 +00:00
|
|
|
fi
|
2011-07-28 16:35:19 +00: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 23:14:36 +00:00
|
|
|
if test $HAVE_DUP2 = 1; then
|
|
|
|
REPLACE_DUP2=1
|
|
|
|
fi
|
2011-07-28 16:35:19 +00:00
|
|
|
fi
|
|
|
|
])
|
2011-06-25 08:40:38 +00: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 21:30:18 +00:00
|
|
|
|
|
|
|
# Prerequisites of lib/dup2.c.
|
|
|
|
AC_DEFUN([gl_PREREQ_DUP2], [])
|