summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorrobert <robert@FreeBSD.org>2002-06-23 20:41:30 +0000
committerrobert <robert@FreeBSD.org>2002-06-23 20:41:30 +0000
commit99a72e8b2b86de02565bcb2874ef95844f82f8a0 (patch)
tree31c6d604aabb6862f4abbd679cc605e59e7fd9a1 /lib
parent9ffcd90b2fb816d7014f3432bfbcab8fb5d7bd81 (diff)
downloadFreeBSD-src-99a72e8b2b86de02565bcb2874ef95844f82f8a0.zip
FreeBSD-src-99a72e8b2b86de02565bcb2874ef95844f82f8a0.tar.gz
Fix a bug which prevented the duplication of the standard i/o
file descriptors in programs linked with libc_r with flags other than the default ones. This kept, inter alia, freopen() from working correctly when reopening standard streams. reviewed by: deischen PR: misc/39377
Diffstat (limited to 'lib')
-rw-r--r--lib/libc_r/uthread/uthread_dup2.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/libc_r/uthread/uthread_dup2.c b/lib/libc_r/uthread/uthread_dup2.c
index af0e32a..d8cead7 100644
--- a/lib/libc_r/uthread/uthread_dup2.c
+++ b/lib/libc_r/uthread/uthread_dup2.c
@@ -58,21 +58,32 @@ _dup2(int fd, int newfd)
if (!(newfd_opened = (_thread_fd_table[newfd] != NULL)) ||
(ret = _FD_LOCK(newfd, FD_RDWR, NULL)) == 0) {
/* Perform the 'dup2' syscall: */
- if ((ret = __sys_dup2(fd, newfd)) < 0) {
- }
- /* Initialise the file descriptor table entry: */
- else if (_thread_fd_table_init(ret) != 0) {
- /* Quietly close the file: */
- __sys_close(ret);
-
- /* Reset the file descriptor: */
- ret = -1;
- } else {
+ ret = __sys_dup2(fd, newfd);
+ if (ret >= 0) {
/*
- * Save the file open flags so that they can
- * be checked later:
+ * If we are duplicating one of the standard
+ * file descriptors, update its flags in the
+ * table of pthread stdio descriptor flags.
*/
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
+ if (ret < 3) {
+ _pthread_stdio_flags[ret] =
+ _thread_fd_table[fd]->flags;
+ }
+ /* Initialise the file descriptor table entry */
+ if (_thread_fd_table_init(ret) != 0) {
+ /* Quietly close the file: */
+ __sys_close(ret);
+
+ /* Reset the file descriptor: */
+ ret = -1;
+ } else {
+ /*
+ * Save the file open flags so that
+ * they can be checked later:
+ */
+ _thread_fd_table[ret]->flags =
+ _thread_fd_table[fd]->flags;
+ }
}
/* Unlock the file descriptor: */
OpenPOWER on IntegriCloud