summaryrefslogtreecommitdiffstats
path: root/lib/libc_r/uthread/uthread_dup.c
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1996-01-22 00:23:58 +0000
committerjulian <julian@FreeBSD.org>1996-01-22 00:23:58 +0000
commit529743d354ac402b1302b397159146fa46c180c5 (patch)
treed93df8a19a0cab699bfc2c0b9e4bc691251efa16 /lib/libc_r/uthread/uthread_dup.c
parent619b731f5bb5e09dcf1eaf1fbd96383ca64398fd (diff)
downloadFreeBSD-src-529743d354ac402b1302b397159146fa46c180c5.zip
FreeBSD-src-529743d354ac402b1302b397159146fa46c180c5.tar.gz
Reviewed by: julian
Submitted by: john birrel One version of the pthreads library another will follow with differnt actions under some cases.. not QUITE complete
Diffstat (limited to 'lib/libc_r/uthread/uthread_dup.c')
-rw-r--r--lib/libc_r/uthread/uthread_dup.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/libc_r/uthread/uthread_dup.c b/lib/libc_r/uthread/uthread_dup.c
new file mode 100644
index 0000000..e6c4598
--- /dev/null
+++ b/lib/libc_r/uthread/uthread_dup.c
@@ -0,0 +1,37 @@
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+int
+dup(int fd)
+{
+ int ret;
+
+ /* Lock the file descriptor: */
+ if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL, __FILE__, __LINE__)) == 0) {
+ /* Perform the 'dup' syscall: */
+ if ((ret = _thread_sys_dup(fd)) < 0) {
+ }
+ /* Initialise the file descriptor table entry: */
+ else if (_thread_fd_table_init(ret) != 0) {
+ /* Quietly close the file: */
+ _thread_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: */
+ _thread_fd_unlock(fd, FD_RDWR);
+ }
+ /* Return the completion status: */
+ return (ret);
+}
+#endif
OpenPOWER on IntegriCloud