1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Assume that dup3 is available

This commit is contained in:
Florian Weimer
2017-04-18 14:42:19 +02:00
parent 46d8874d5b
commit b48061e1a5
9 changed files with 21 additions and 82 deletions

View File

@ -78,32 +78,9 @@ freopen (const char *filename, const char *mode, FILE *fp)
if (fd != -1)
{
#ifdef O_CLOEXEC
# ifndef __ASSUME_DUP3
int newfd;
if (__have_dup3 < 0)
newfd = -1;
else
newfd =
# endif
__dup3 (_IO_fileno (result), fd,
(result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
? O_CLOEXEC : 0);
#else
# define newfd 1
#endif
#ifndef __ASSUME_DUP3
if (newfd < 0)
{
if (errno == ENOSYS)
__have_dup3 = -1;
__dup2 (_IO_fileno (result), fd);
if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
__fcntl (fd, F_SETFD, FD_CLOEXEC);
}
#endif
__dup3 (_IO_fileno (result), fd,
(result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
? O_CLOEXEC : 0);
__close (_IO_fileno (result));
_IO_fileno (result) = fd;
}