aboutsummaryrefslogtreecommitdiff
path: root/lib/libc_r/uthread
diff options
context:
space:
mode:
authorRobert Drehmel <robert@FreeBSD.org>2002-06-23 20:41:30 +0000
committerRobert Drehmel <robert@FreeBSD.org>2002-06-23 20:41:30 +0000
commit4b571b192a221cd05dc140113373acf5aee7ca24 (patch)
tree31c6d604aabb6862f4abbd679cc605e59e7fd9a1 /lib/libc_r/uthread
parent04b681a9997c2f9d5a5e3f7edfffeda6296121b3 (diff)
Notes
Diffstat (limited to 'lib/libc_r/uthread')
-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 af0e32aff5b5..d8cead7f3c62 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: */