[前][次][番号順一覧][スレッド一覧]

ruby-changes:66112

From: Nobuyoshi <ko1@a...>
Date: Mon, 10 May 2021 15:59:46 +0900 (JST)
Subject: [ruby-changes:66112] 2d67027448 (master): Removed missing/dup2.c

https://git.ruby-lang.org/ruby.git/commit/?id=2d67027448

From 2d670274481647bf3bc9c82a9472bc8500a97a45 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 1 May 2021 22:07:46 +0900
Subject: Removed missing/dup2.c

This function should be always available, as POSIX-compliant or
Windows platform are required since 1.9.  Also the code in this
file is MT-unsafe.
---
 LEGAL                  |  1 -
 configure.ac           |  9 ++++++--
 include/ruby/missing.h |  4 ----
 io.c                   |  4 +---
 missing/dup2.c         | 60 --------------------------------------------------
 5 files changed, 8 insertions(+), 70 deletions(-)
 delete mode 100644 missing/dup2.c

diff --git a/LEGAL b/LEGAL
index f960607..ecd1e16 100644
--- a/LEGAL
+++ b/LEGAL
@@ -531,7 +531,6 @@ mentioned below. https://github.com/ruby/ruby/blob/trunk/LEGAL#L531
 [include/ruby/st.h]
 [missing/acosh.c]
 [missing/alloca.c]
-[missing/dup2.c]
 [missing/erf.c]
 [missing/finite.c]
 [missing/hypot.c]
diff --git a/configure.ac b/configure.ac
index e781da0..a1a0872 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1858,10 +1858,16 @@ AS_CASE(["$target_os"],[freebsd*],[ https://github.com/ruby/ruby/blob/trunk/configure.ac#L1858
 	 AC_REPLACE_FUNCS(close)
 	 ])
 
+AC_DEFUN([RUBY_REQUIRE_FUNC], [
+    AC_CHECK_FUNCS([$1])
+    AS_IF([test "$ac_cv_func_[]AS_TR_SH($1)" = yes], [],
+          [AC_MSG_ERROR($1[() must be supported])])
+])
+m4_map_args_w([dup dup2], [RUBY_REQUIRE_FUNC(], [)])
+
 AC_REPLACE_FUNCS(acosh)
 AC_REPLACE_FUNCS(cbrt)
 AC_REPLACE_FUNCS(crypt)
-AC_REPLACE_FUNCS(dup2)
 AC_REPLACE_FUNCS(erf)
 AC_REPLACE_FUNCS(explicit_bzero)
 AC_REPLACE_FUNCS(ffs)
@@ -1922,7 +1928,6 @@ AC_CHECK_FUNCS(dirfd) https://github.com/ruby/ruby/blob/trunk/configure.ac#L1928
 AC_CHECK_FUNCS(dl_iterate_phdr)
 AC_CHECK_FUNCS(dlopen)
 AC_CHECK_FUNCS(dladdr)
-AC_CHECK_FUNCS(dup)
 AC_CHECK_FUNCS(dup3)
 AC_CHECK_FUNCS(eaccess)
 AC_CHECK_FUNCS(endgrent)
diff --git a/include/ruby/missing.h b/include/ruby/missing.h
index f83f1b6..7d55124 100644
--- a/include/ruby/missing.h
+++ b/include/ruby/missing.h
@@ -84,10 +84,6 @@ RUBY_EXTERN double atanh(double); https://github.com/ruby/ruby/blob/trunk/include/ruby/missing.h#L84
 RUBY_EXTERN char *crypt(const char *, const char *);
 #endif
 
-#ifndef HAVE_DUP2
-RUBY_EXTERN int dup2(int, int);
-#endif
-
 #ifndef HAVE_EACCESS
 RUBY_EXTERN int eaccess(const char*, int);
 #endif
diff --git a/io.c b/io.c
index 371d6ce..32b367f 100644
--- a/io.c
+++ b/io.c
@@ -462,7 +462,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd) https://github.com/ruby/ruby/blob/trunk/io.c#L462
     }
 #elif defined(HAVE_FCNTL) && defined(F_DUPFD)
     ret = fcntl(fd, F_DUPFD, minfd);
-#elif defined(HAVE_DUP)
+#else
     ret = dup(fd);
     if (ret >= 0 && ret < minfd) {
         const int prev_fd = ret;
@@ -470,8 +470,6 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd) https://github.com/ruby/ruby/blob/trunk/io.c#L470
         close(prev_fd);
     }
     return ret;
-#else
-# error "dup() or fcntl(F_DUPFD) must be supported."
 #endif
     if (ret < 0) return ret;
     rb_maygvl_fd_fix_cloexec(ret);
diff --git a/missing/dup2.c b/missing/dup2.c
deleted file mode 100644
index 7f2b78c..0000000
--- a/missing/dup2.c
+++ /dev/null
@@ -1,60 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/io.c#L0
-/*
- * Public domain dup2() lookalike
- * by Curtis Jackson @ AT&T Technologies, Burlington, NC
- * electronic address:  burl!rcj
- *
- * dup2 performs the following functions:
- *
- * Check to make sure that fd1 is a valid open file descriptor.
- * Check to see if fd2 is already open; if so, close it.
- * Duplicate fd1 onto fd2; checking to make sure fd2 is a valid fd.
- * Return fd2 if all went well; return BADEXIT otherwise.
- */
-
-#include "ruby/internal/config.h"
-
-#if defined(HAVE_FCNTL)
-# include <fcntl.h>
-#endif
-
-#if !defined(HAVE_FCNTL) || !defined(F_DUPFD)
-# include <errno.h>
-#endif
-
-#define BADEXIT -1
-
-int
-dup2(int fd1, int fd2)
-{
-#if defined(HAVE_FCNTL) && defined(F_DUPFD)
-	if (fd1 != fd2) {
-#ifdef F_GETFL
-		if (fcntl(fd1, F_GETFL) < 0)
-			return BADEXIT;
-		if (fcntl(fd2, F_GETFL) >= 0)
-			close(fd2);
-#else
-		close(fd2);
-#endif
-		if (fcntl(fd1, F_DUPFD, fd2) < 0)
-			return BADEXIT;
-	}
-	return fd2;
-#else
-	extern int errno;
-	int i, fd, fds[256];
-
-	if (fd1 == fd2) return 0;
-	close(fd2);
-	for (i=0; i<256; i++) {
-		fd = fds[i] = dup(fd1);
-		if (fd == fd2) break;
-	}
-	while (i) {
-	    	close(fds[i--]);
-	}
-	if (fd == fd2) return 0;
-	errno = EMFILE;
-	return BADEXIT;
-#endif
-}
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]