diff options
author | jb <jb@FreeBSD.org> | 1998-06-10 22:24:12 +0000 |
---|---|---|
committer | jb <jb@FreeBSD.org> | 1998-06-10 22:24:12 +0000 |
commit | cccdaf6051b023c2e52ce8373964045e54418380 (patch) | |
tree | 97ed6dffba2c384085ae329ab283118093d16734 /lib/libc_r | |
parent | da325152ee7d80e6b66c019c91f622ce1aa59c55 (diff) | |
download | FreeBSD-src-cccdaf6051b023c2e52ce8373964045e54418380.zip FreeBSD-src-cccdaf6051b023c2e52ce8373964045e54418380.tar.gz |
When doing a F_SETFL, read the flags back so that the ones stored
in the file descriptor table are exactly what the kernel knows subject
to the O_NONBLOCK flag being requested by the user.
Diffstat (limited to 'lib/libc_r')
-rw-r--r-- | lib/libc_r/uthread/uthread_fcntl.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/libc_r/uthread/uthread_fcntl.c b/lib/libc_r/uthread/uthread_fcntl.c index 556bd1f..eecda60 100644 --- a/lib/libc_r/uthread/uthread_fcntl.c +++ b/lib/libc_r/uthread/uthread_fcntl.c @@ -41,6 +41,7 @@ int fcntl(int fd, int cmd,...) { int flags = 0; + int nonblock; int oldfd; int ret; int status; @@ -90,10 +91,37 @@ fcntl(int fd, int cmd,...) ret = _thread_fd_table[fd]->flags; break; case F_SETFL: + /* + * Get the file descriptor flags passed by the + * caller: + */ flags = va_arg(ap, int); - if ((ret = _thread_sys_fcntl(fd, cmd, flags | O_NONBLOCK)) == 0) { - _thread_fd_table[fd]->flags = flags; - } + + /* + * Check if the user wants a non-blocking file + * descriptor: + */ + nonblock = flags & O_NONBLOCK; + + /* Set the file descriptor flags: */ + if ((ret = _thread_sys_fcntl(fd, cmd, flags | O_NONBLOCK)) != 0) { + + /* Get the flags so that we behave like the kernel: */ + } else if ((flags = _thread_sys_fcntl(fd, + F_GETFL, 0)) == -1) { + /* Error getting flags: */ + ret = -1; + + /* + * Check if the file descriptor is non-blocking + * with respect to the user: + */ + } else if (nonblock) + /* A non-blocking descriptor: */ + _thread_fd_table[fd]->flags = flags | O_NONBLOCK; + else + /* Save the flags: */ + _thread_fd_table[fd]->flags = flags & ~O_NONBLOCK; break; default: /* Might want to make va_arg use a union */ |