]> Savannah Git Hosting - gnulib.git/commitdiff
dup2: Remove support for some very old platforms.
authorBruno Haible <bruno@clisp.org>
Wed, 8 Jul 2020 00:52:09 +0000 (02:52 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 8 Jul 2020 01:12:47 +0000 (03:12 +0200)
* 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'.

ChangeLog
doc/posix-functions/dup2.texi
lib/dup2.c
lib/unistd.in.h
m4/dup2-obsolete.m4 [deleted file]
m4/dup2.m4
m4/unistd_h.m4
modules/dup2
modules/dup2-obsolete [deleted file]
modules/unistd

index 5d0ba8243856f0c788106207b245b3366a50a404..8d0ccf56dae3023c8d582fd31068be5b52bf05bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
index 8635e6c0895b8964e2aeb300c329309c3cb39a36..d81def5cddb71fb08511dfc71071d1e4a399ff92 100644 (file)
@@ -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
index 88ef2591313a0f2ab92b5f421dbd84c60911ff04..9bc3951f3d2cd71236b65b46b4022561c7ec1011 100644 (file)
 #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 */
index 71904fe5d926c6f155c1698449c8e8a5ff2cd16e..3a4981391139b0e018becc9af87c088ba3d1e6eb 100644 (file)
@@ -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 (file)
index 5e72403..0000000
+++ /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.
-  :
-])
index 21b1ecc26b8d6f3177015f8b42c567bbd154d46b..462bfd0e526956f2e4e88ebdd038f40e65657343 100644 (file)
@@ -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
   ])
 ])
index dfa38f85d60151e19884a45455afd68ff51f2e1e..b4734daf603cf6e502c3b3d870aeba4d89713195 100644 (file)
@@ -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])
index 2ad65d1dc11b63dc249ea689280722f9bec7b82c..70a28ded6925f33f4fe50c565b09acde33610968 100644 (file)
@@ -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 (file)
index 243bed1..0000000
+++ /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
index 5550646943513223f1df8b9c9d19c32df2e25bad..b14faaaf6465218ce919d3be1252fa74e25cc449 100644 (file)
@@ -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' \