mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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.
This commit is contained in:
parent
1d0e670e91
commit
2d67027448
Notes:
git
2021-05-10 15:59:48 +09:00
5 changed files with 8 additions and 70 deletions
1
LEGAL
1
LEGAL
|
@ -531,7 +531,6 @@ mentioned below.
|
|||
[include/ruby/st.h]
|
||||
[missing/acosh.c]
|
||||
[missing/alloca.c]
|
||||
[missing/dup2.c]
|
||||
[missing/erf.c]
|
||||
[missing/finite.c]
|
||||
[missing/hypot.c]
|
||||
|
|
|
@ -1858,10 +1858,16 @@ AS_CASE(["$target_os"],[freebsd*],[
|
|||
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)
|
|||
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)
|
||||
|
|
|
@ -84,10 +84,6 @@ RUBY_EXTERN double atanh(double);
|
|||
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
|
||||
|
|
4
io.c
4
io.c
|
@ -462,7 +462,7 @@ rb_cloexec_fcntl_dupfd(int fd, int minfd)
|
|||
}
|
||||
#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)
|
|||
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);
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
}
|
Loading…
Add table
Reference in a new issue