summaryrefslogtreecommitdiffstats
path: root/lib/libc_r
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc_r')
-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