aboutsummaryrefslogtreecommitdiff
path: root/lib/libc_r/uthread/uthread_fd.c
diff options
context:
space:
mode:
authorJulian Elischer <julian@FreeBSD.org>1996-08-20 08:22:01 +0000
committerJulian Elischer <julian@FreeBSD.org>1996-08-20 08:22:01 +0000
commit0f7d684755aefbcfd70b45d24efc2d39bc505c4c (patch)
treeb14348030d1048f8628b798374a8a061a990aae3 /lib/libc_r/uthread/uthread_fd.c
parent1bbb22c82e47dbc805e523be5e2fe3d4436761e0 (diff)
Notes
Diffstat (limited to 'lib/libc_r/uthread/uthread_fd.c')
-rw-r--r--lib/libc_r/uthread/uthread_fd.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c
index b41631aa6269..ad6e9f39aec8 100644
--- a/lib/libc_r/uthread/uthread_fd.c
+++ b/lib/libc_r/uthread/uthread_fd.c
@@ -31,6 +31,7 @@
*
*/
#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
@@ -48,7 +49,7 @@ _thread_fd_table_init(int fd)
/* Check if the file descriptor is out of range: */
if (fd < 0 || fd >= _thread_dtablesize) {
/* Return a bad file descriptor error: */
- _thread_seterrno(_thread_run, EBADF);
+ errno = EBADF;
ret = -1;
}
/*
@@ -60,7 +61,7 @@ _thread_fd_table_init(int fd)
/* Allocate memory for the file descriptor table entry: */
else if ((_thread_fd_table[fd] = (struct fd_table_entry *) malloc(sizeof(struct fd_table_entry))) == NULL) {
/* Return a bad file descriptor error: */
- _thread_seterrno(_thread_run, EBADF);
+ errno = EBADF;
ret = -1;
} else {
/* Initialise the file locks: */
@@ -73,12 +74,25 @@ _thread_fd_table_init(int fd)
_thread_fd_table[fd]->r_lockcount = 0;;
_thread_fd_table[fd]->w_lockcount = 0;;
- /* Default the flags: */
- _thread_fd_table[fd]->flags = 0;
-
/* Initialise the read/write queues: */
_thread_queue_init(&_thread_fd_table[fd]->r_queue);
_thread_queue_init(&_thread_fd_table[fd]->w_queue);
+
+ /* Get the flags for the file: */
+ if ((_thread_fd_table[fd]->flags = _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) {
+ ret = -1;
+
+ /* Make the file descriptor non-blocking: */
+ } else {
+ _thread_sys_fcntl(fd, F_SETFL, _thread_fd_table[fd]->flags | O_NONBLOCK);
+ }
+
+ /* Check if one of the fcntl calls failed: */
+ if (ret == -1) {
+ /* Free the file descriptor table entry: */
+ free(_thread_fd_table[fd]);
+ _thread_fd_table[fd] = NULL;
+ }
}
/* Unblock signals: */