summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-07-08 02:52:09 +0200
committerBruno Haible <bruno@clisp.org>2020-07-08 03:12:47 +0200
commitcfcb5fc6b95ca04bd3c8637d4027641d07c15cbe (patch)
tree11bd6a12dd42597de1210e3f08726e0692cbe64d
parent8e867216109f764c195790a53f67bf1bc925b27f (diff)
downloadgnulib-cfcb5fc6b95ca04bd3c8637d4027641d07c15cbe.tar.gz
gnulib-cfcb5fc6b95ca04bd3c8637d4027641d07c15cbe.tar.bz2
dup2: Remove support for some very old platforms.
* m4/dup2-obsolete.m4: Remove file. * modules/dup2-obsolete: Remove file. * m4/dup2.m4 (gl_FUNC_DUP2): Assume module 'dup2-obsolete' is absent. Don't define HAVE_DUP2. * lib/unistd.in.h (dup2): Assume HAVE_DUP2 is 1. * lib/dup2.c: Likewise. * modules/dup2 (Depends-on, configure.ac): Likewise. (Depends-on): Remove dup2-obsolete. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Don't initialize HAVE_DUP2. * modules/unistd (Makefile.am): Don't substitute HAVE_DUP2. * doc/posix-functions/dup2.texi: Don't mention module 'dup2-obsolete'.
-rw-r--r--ChangeLog15
-rw-r--r--doc/posix-functions/dup2.texi10
-rw-r--r--lib/dup2.c100
-rw-r--r--lib/unistd.in.h3
-rw-r--r--m4/dup2-obsolete.m411
-rw-r--r--m4/dup2.m4181
-rw-r--r--m4/unistd_h.m43
-rw-r--r--modules/dup27
-rw-r--r--modules/dup2-obsolete28
-rw-r--r--modules/unistd1
10 files changed, 132 insertions, 227 deletions
diff --git a/ChangeLog b/ChangeLog
index 5d0ba82438..8d0ccf56da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2020-07-07 Bruno Haible <bruno@clisp.org>
+ dup2: Remove support for some very old platforms.
+ * m4/dup2-obsolete.m4: Remove file.
+ * modules/dup2-obsolete: Remove file.
+ * m4/dup2.m4 (gl_FUNC_DUP2): Assume module 'dup2-obsolete' is absent.
+ Don't define HAVE_DUP2.
+ * lib/unistd.in.h (dup2): Assume HAVE_DUP2 is 1.
+ * lib/dup2.c: Likewise.
+ * modules/dup2 (Depends-on, configure.ac): Likewise.
+ (Depends-on): Remove dup2-obsolete.
+ * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Don't initialize HAVE_DUP2.
+ * modules/unistd (Makefile.am): Don't substitute HAVE_DUP2.
+ * doc/posix-functions/dup2.texi: Don't mention module 'dup2-obsolete'.
+
+2020-07-07 Bruno Haible <bruno@clisp.org>
+
canonicalize: Trim module dependencies.
* lib/hash-triple.h: Group declarations.
* lib/hash-triple-simple.c: New file, extracted from lib/hash-triple.c.
diff --git a/doc/posix-functions/dup2.texi b/doc/posix-functions/dup2.texi
index 8635e6c089..d81def5cdd 100644
--- a/doc/posix-functions/dup2.texi
+++ b/doc/posix-functions/dup2.texi
@@ -4,9 +4,9 @@
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html}
-Gnulib module: dup2 or dup2-obsolete
+Gnulib module: dup2
-Portability problems fixed by either Gnulib module @code{dup2} or @code{dup2-obsolete}:
+Portability problems fixed by Gnulib:
@itemize
@item
This function is declared in a different header file (namely, @code{<io.h>})
@@ -53,12 +53,6 @@ large targets, which interferes with using
AIX 7.1, FreeBSD 6.1, Cygwin 1.5.
@end itemize
-Portability problems fixed by Gnulib module @code{dup2-obsolete}:
-@itemize
-@item
-This function is missing on some older platforms.
-@end itemize
-
Portability problems not fixed by Gnulib:
@itemize
@end itemize
diff --git a/lib/dup2.c b/lib/dup2.c
index 88ef259131..9bc3951f3d 100644
--- a/lib/dup2.c
+++ b/lib/dup2.c
@@ -25,28 +25,26 @@
#include <errno.h>
#include <fcntl.h>
-#if HAVE_DUP2
+#undef dup2
-# undef dup2
-
-# if defined _WIN32 && ! defined __CYGWIN__
+#if defined _WIN32 && ! defined __CYGWIN__
/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
-# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-# include "msvc-inval.h"
-# endif
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+# endif
/* Get _get_osfhandle. */
-# if GNULIB_MSVC_NOTHROW
-# include "msvc-nothrow.h"
-# else
-# include <io.h>
-# endif
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
-# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
static int
dup2_nothrow (int fd, int desired_fd)
{
@@ -65,9 +63,9 @@ dup2_nothrow (int fd, int desired_fd)
return result;
}
-# else
-# define dup2_nothrow dup2
-# endif
+# else
+# define dup2_nothrow dup2
+# endif
static int
ms_windows_dup2 (int fd, int desired_fd)
@@ -103,11 +101,11 @@ ms_windows_dup2 (int fd, int desired_fd)
return result;
}
-# define dup2 ms_windows_dup2
+# define dup2 ms_windows_dup2
-# elif defined __KLIBC__
+#elif defined __KLIBC__
-# include <InnoTekLIBC/backend.h>
+# include <InnoTekLIBC/backend.h>
static int
klibc_dup2dirfd (int fd, int desired_fd)
@@ -155,81 +153,37 @@ klibc_dup2 (int fd, int desired_fd)
return dupfd;
}
-# define dup2 klibc_dup2
-# endif
+# define dup2 klibc_dup2
+#endif
int
rpl_dup2 (int fd, int desired_fd)
{
int result;
-# ifdef F_GETFL
+#ifdef F_GETFL
/* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
On Cygwin 1.5.x, dup2 (1, 1) returns 0.
On Cygwin 1.7.17, dup2 (1, -1) dumps core.
On Cygwin 1.7.25, dup2 (1, 256) can dump core.
On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
-# if HAVE_SETDTABLESIZE
+# if HAVE_SETDTABLESIZE
setdtablesize (desired_fd + 1);
-# endif
+# endif
if (desired_fd < 0)
fd = desired_fd;
if (fd == desired_fd)
return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
-# endif
+#endif
result = dup2 (fd, desired_fd);
/* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
if (result == -1 && errno == EMFILE)
errno = EBADF;
-# if REPLACE_FCHDIR
+#if REPLACE_FCHDIR
if (fd != desired_fd && result != -1)
result = _gl_register_dup (fd, result);
-# endif
- return result;
-}
-
-#else /* !HAVE_DUP2 */
-
-/* On older platforms, dup2 did not exist. */
-
-# ifndef F_DUPFD
-static int
-dupfd (int fd, int desired_fd)
-{
- int duplicated_fd = dup (fd);
- if (duplicated_fd < 0 || duplicated_fd == desired_fd)
- return duplicated_fd;
- else
- {
- int r = dupfd (fd, desired_fd);
- int e = errno;
- close (duplicated_fd);
- errno = e;
- return r;
- }
-}
-# endif
-
-int
-dup2 (int fd, int desired_fd)
-{
- int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
- if (result == -1 || fd == desired_fd)
- return result;
- close (desired_fd);
-# ifdef F_DUPFD
- result = fcntl (fd, F_DUPFD, desired_fd);
-# if REPLACE_FCHDIR
- if (0 <= result)
- result = _gl_register_dup (fd, result);
-# endif
-# else
- result = dupfd (fd, desired_fd);
-# endif
- if (result == -1 && (errno == EMFILE || errno == EINVAL))
- errno = EBADF;
+#endif
return result;
}
-#endif /* !HAVE_DUP2 */
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 71904fe5d9..3a49813911 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -408,9 +408,6 @@ _GL_WARN_ON_USE (dup, "dup is unportable - "
_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
# else
-# if !@HAVE_DUP2@
-_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
-# endif
_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
# endif
_GL_CXXALIASWARN (dup2);
diff --git a/m4/dup2-obsolete.m4 b/m4/dup2-obsolete.m4
deleted file mode 100644
index 5e72403337..0000000000
--- a/m4/dup2-obsolete.m4
+++ /dev/null
@@ -1,11 +0,0 @@
-# dup2-obsolete.m4 serial 1
-dnl Copyright (C) 2011-2020 Free Software Foundation, Inc.
-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_OBSOLETE],
-[
- dnl The real code is in dup2.m4.
- :
-])
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index 21b1ecc26b..462bfd0e52 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,4 +1,4 @@
-#serial 25
+#serial 26
dnl Copyright (C) 2002, 2005, 2007, 2009-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -8,107 +8,94 @@ 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([
- AC_LANG_PROGRAM(
- [[#include <errno.h>
- #include <fcntl.h>
- #include <limits.h>
- #include <sys/resource.h>
- #include <unistd.h>
- #ifndef RLIM_SAVED_CUR
- # define RLIM_SAVED_CUR RLIM_INFINITY
- #endif
- #ifndef RLIM_SAVED_MAX
- # define RLIM_SAVED_MAX RLIM_INFINITY
- #endif
- ]],
- [[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
- if (dup2 (1, 1) != 1)
- 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);
- /* 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);
- }
- return result;]])
- ],
- [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
- gl_cv_func_dup2_works="guessing no" ;;
- cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
- gl_cv_func_dup2_works="guessing no" ;;
- aix* | freebsd*)
- # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
- # not EBADF.
- gl_cv_func_dup2_works="guessing no" ;;
- haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
- gl_cv_func_dup2_works="guessing no" ;;
- *-android*) # implemented using dup3(), which fails if oldfd == newfd
- gl_cv_func_dup2_works="guessing no" ;;
- os2*) # on OS/2 kLIBC, dup2() does not work on a directory fd.
- gl_cv_func_dup2_works="guessing no" ;;
- *) gl_cv_func_dup2_works="guessing yes" ;;
- esac])
- ])
- case "$gl_cv_func_dup2_works" in
- *yes) ;;
- *)
- REPLACE_DUP2=1
- AC_CHECK_FUNCS([setdtablesize])
- ;;
- esac
- fi
+ AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
+ [AC_RUN_IFELSE([
+ AC_LANG_PROGRAM(
+ [[#include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
+ #include <sys/resource.h>
+ #include <unistd.h>
+ #ifndef RLIM_SAVED_CUR
+ # define RLIM_SAVED_CUR RLIM_INFINITY
+ #endif
+ #ifndef RLIM_SAVED_MAX
+ # define RLIM_SAVED_MAX RLIM_INFINITY
+ #endif
+ ]],
+ [[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
+ if (dup2 (1, 1) != 1)
+ 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);
+ /* 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);
+ }
+ return result;]])
+ ],
+ [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
+ gl_cv_func_dup2_works="guessing no" ;;
+ cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
+ gl_cv_func_dup2_works="guessing no" ;;
+ aix* | freebsd*)
+ # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
+ # not EBADF.
+ gl_cv_func_dup2_works="guessing no" ;;
+ haiku*) # on Haiku alpha 2, dup2(1, 1) resets FD_CLOEXEC.
+ gl_cv_func_dup2_works="guessing no" ;;
+ *-android*) # implemented using dup3(), which fails if oldfd == newfd
+ gl_cv_func_dup2_works="guessing no" ;;
+ os2*) # on OS/2 kLIBC, dup2() does not work on a directory fd.
+ gl_cv_func_dup2_works="guessing no" ;;
+ *) gl_cv_func_dup2_works="guessing yes" ;;
+ esac])
+ ])
+ case "$gl_cv_func_dup2_works" in
+ *yes) ;;
+ *)
+ REPLACE_DUP2=1
+ AC_CHECK_FUNCS([setdtablesize])
+ ;;
+ esac
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
- if test $HAVE_DUP2 = 1; then
- REPLACE_DUP2=1
- fi
+ REPLACE_DUP2=1
fi
])
])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index dfa38f85d6..b4734daf60 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 80
+# unistd_h.m4 serial 81
dnl Copyright (C) 2006-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -120,7 +120,6 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN])
HAVE_COPY_FILE_RANGE=1; AC_SUBST([HAVE_COPY_FILE_RANGE])
- HAVE_DUP2=1; AC_SUBST([HAVE_DUP2])
HAVE_DUP3=1; AC_SUBST([HAVE_DUP3])
HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS])
HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT])
diff --git a/modules/dup2 b/modules/dup2
index 2ad65d1dc1..70a28ded69 100644
--- a/modules/dup2
+++ b/modules/dup2
@@ -7,13 +7,12 @@ m4/dup2.m4
Depends-on:
unistd
-dup2-obsolete
-msvc-inval [test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1]
-msvc-nothrow [test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1]
+msvc-inval [test $REPLACE_DUP2 = 1]
+msvc-nothrow [test $REPLACE_DUP2 = 1]
configure.ac:
gl_FUNC_DUP2
-if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then
+if test $REPLACE_DUP2 = 1; then
AC_LIBOBJ([dup2])
gl_PREREQ_DUP2
fi
diff --git a/modules/dup2-obsolete b/modules/dup2-obsolete
deleted file mode 100644
index 243bed1fc2..0000000000
--- a/modules/dup2-obsolete
+++ /dev/null
@@ -1,28 +0,0 @@
-Description:
-dup2() function for old platforms.
-
-Status:
-obsolete
-
-Notice:
-This module is obsolete.
-
-Files:
-m4/dup2-obsolete.m4
-
-Depends-on:
-dup2
-
-configure.ac:
-gl_FUNC_DUP2_OBSOLETE
-
-Makefile.am:
-
-Include:
-<unistd.h>
-
-License:
-LGPLv2+
-
-Maintainer:
-all
diff --git a/modules/unistd b/modules/unistd
index 5550646943..b14faaaf64 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -94,7 +94,6 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
< $(srcdir)/unistd.in.h | \
sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
-e 's|@''HAVE_COPY_FILE_RANGE''@|$(HAVE_COPY_FILE_RANGE)|g' \
- -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
-e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
-e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
-e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \

Return to:

Send suggestions and report system problems to the System administrator.