diff options
Diffstat (limited to 'lib/libkse/thread/thr_readv.c')
-rw-r--r-- | lib/libkse/thread/thr_readv.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/libkse/thread/thr_readv.c b/lib/libkse/thread/thr_readv.c index 0a19290b..819e20c 100644 --- a/lib/libkse/thread/thr_readv.c +++ b/lib/libkse/thread/thr_readv.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_readv.c,v 1.4 1998/04/29 09:59:11 jb Exp $ + * $Id: uthread_readv.c,v 1.5 1998/06/09 23:20:54 jb Exp $ * */ #include <sys/types.h> @@ -45,9 +45,21 @@ ssize_t readv(int fd, const struct iovec * iov, int iovcnt) { int ret; + int type; /* Lock the file descriptor for read: */ if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for read: */ + if (type != O_RDONLY && type != O_RDWR) { + /* File is not open for read: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_READ); + return (-1); + } + /* Perform a non-blocking readv syscall: */ while ((ret = _thread_sys_readv(fd, iov, iovcnt)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && |