diff options
| author | John Birrell <jb@FreeBSD.org> | 1998-06-10 22:28:45 +0000 |
|---|---|---|
| committer | John Birrell <jb@FreeBSD.org> | 1998-06-10 22:28:45 +0000 |
| commit | 8eb25828ad86a9625c67e1d65849a7bfc28d853e (patch) | |
| tree | e3897c941535c26222a6d0846c0bc41f73b296bc | |
| parent | aef774b0d5a560d4121597e4450ba03a52dfd351 (diff) | |
Notes
| -rw-r--r-- | lib/libc_r/uthread/uthread_read.c | 14 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_readv.c | 14 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_write.c | 14 | ||||
| -rw-r--r-- | lib/libc_r/uthread/uthread_writev.c | 14 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_read.c | 14 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_readv.c | 14 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_write.c | 14 | ||||
| -rw-r--r-- | lib/libkse/thread/thr_writev.c | 14 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_read.c | 14 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_readv.c | 14 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_write.c | 14 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_writev.c | 14 |
12 files changed, 156 insertions, 12 deletions
diff --git a/lib/libc_r/uthread/uthread_read.c b/lib/libc_r/uthread/uthread_read.c index 358a6209714c..6c4d21121876 100644 --- a/lib/libc_r/uthread/uthread_read.c +++ b/lib/libc_r/uthread/uthread_read.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_read.c,v 1.4 1998/04/29 09:59:10 jb Exp $ + * $Id: uthread_read.c,v 1.5 1998/06/09 23:20:53 jb Exp $ * */ #include <sys/types.h> @@ -45,6 +45,7 @@ ssize_t read(int fd, void *buf, size_t nbytes) { int ret; + int type; /* POSIX says to do just this: */ if (nbytes == 0) @@ -52,6 +53,17 @@ read(int fd, void *buf, size_t nbytes) /* 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 read syscall: */ while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && diff --git a/lib/libc_r/uthread/uthread_readv.c b/lib/libc_r/uthread/uthread_readv.c index 0a19290b0501..819e20cbc257 100644 --- a/lib/libc_r/uthread/uthread_readv.c +++ b/lib/libc_r/uthread/uthread_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 && diff --git a/lib/libc_r/uthread/uthread_write.c b/lib/libc_r/uthread/uthread_write.c index 78940e2ca218..97320317346e 100644 --- a/lib/libc_r/uthread/uthread_write.c +++ b/lib/libc_r/uthread/uthread_write.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_write.c,v 1.6 1998/05/25 21:45:50 jb Exp $ + * $Id: uthread_write.c,v 1.7 1998/06/09 23:21:04 jb Exp $ * */ #include <sys/types.h> @@ -46,6 +46,7 @@ write(int fd, const void *buf, size_t nbytes) { int blocking; int status; + int type; ssize_t n; ssize_t num = 0; ssize_t ret; @@ -56,6 +57,17 @@ write(int fd, const void *buf, size_t nbytes) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); diff --git a/lib/libc_r/uthread/uthread_writev.c b/lib/libc_r/uthread/uthread_writev.c index 9810aca0d4ef..f5cb7889dd14 100644 --- a/lib/libc_r/uthread/uthread_writev.c +++ b/lib/libc_r/uthread/uthread_writev.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_writev.c,v 1.7 1998/05/27 00:44:58 jb Exp $ + * $Id: uthread_writev.c,v 1.8 1998/06/09 23:21:05 jb Exp $ * */ #include <sys/types.h> @@ -48,6 +48,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) { int blocking; int idx = 0; + int type; ssize_t cnt; ssize_t n; ssize_t num = 0; @@ -71,6 +72,17 @@ writev(int fd, const struct iovec * iov, int iovcnt) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); diff --git a/lib/libkse/thread/thr_read.c b/lib/libkse/thread/thr_read.c index 358a6209714c..6c4d21121876 100644 --- a/lib/libkse/thread/thr_read.c +++ b/lib/libkse/thread/thr_read.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_read.c,v 1.4 1998/04/29 09:59:10 jb Exp $ + * $Id: uthread_read.c,v 1.5 1998/06/09 23:20:53 jb Exp $ * */ #include <sys/types.h> @@ -45,6 +45,7 @@ ssize_t read(int fd, void *buf, size_t nbytes) { int ret; + int type; /* POSIX says to do just this: */ if (nbytes == 0) @@ -52,6 +53,17 @@ read(int fd, void *buf, size_t nbytes) /* 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 read syscall: */ while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && diff --git a/lib/libkse/thread/thr_readv.c b/lib/libkse/thread/thr_readv.c index 0a19290b0501..819e20cbc257 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 && diff --git a/lib/libkse/thread/thr_write.c b/lib/libkse/thread/thr_write.c index 78940e2ca218..97320317346e 100644 --- a/lib/libkse/thread/thr_write.c +++ b/lib/libkse/thread/thr_write.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_write.c,v 1.6 1998/05/25 21:45:50 jb Exp $ + * $Id: uthread_write.c,v 1.7 1998/06/09 23:21:04 jb Exp $ * */ #include <sys/types.h> @@ -46,6 +46,7 @@ write(int fd, const void *buf, size_t nbytes) { int blocking; int status; + int type; ssize_t n; ssize_t num = 0; ssize_t ret; @@ -56,6 +57,17 @@ write(int fd, const void *buf, size_t nbytes) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); diff --git a/lib/libkse/thread/thr_writev.c b/lib/libkse/thread/thr_writev.c index 9810aca0d4ef..f5cb7889dd14 100644 --- a/lib/libkse/thread/thr_writev.c +++ b/lib/libkse/thread/thr_writev.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_writev.c,v 1.7 1998/05/27 00:44:58 jb Exp $ + * $Id: uthread_writev.c,v 1.8 1998/06/09 23:21:05 jb Exp $ * */ #include <sys/types.h> @@ -48,6 +48,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) { int blocking; int idx = 0; + int type; ssize_t cnt; ssize_t n; ssize_t num = 0; @@ -71,6 +72,17 @@ writev(int fd, const struct iovec * iov, int iovcnt) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); diff --git a/lib/libpthread/thread/thr_read.c b/lib/libpthread/thread/thr_read.c index 358a6209714c..6c4d21121876 100644 --- a/lib/libpthread/thread/thr_read.c +++ b/lib/libpthread/thread/thr_read.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_read.c,v 1.4 1998/04/29 09:59:10 jb Exp $ + * $Id: uthread_read.c,v 1.5 1998/06/09 23:20:53 jb Exp $ * */ #include <sys/types.h> @@ -45,6 +45,7 @@ ssize_t read(int fd, void *buf, size_t nbytes) { int ret; + int type; /* POSIX says to do just this: */ if (nbytes == 0) @@ -52,6 +53,17 @@ read(int fd, void *buf, size_t nbytes) /* 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 read syscall: */ while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { if ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && diff --git a/lib/libpthread/thread/thr_readv.c b/lib/libpthread/thread/thr_readv.c index 0a19290b0501..819e20cbc257 100644 --- a/lib/libpthread/thread/thr_readv.c +++ b/lib/libpthread/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 && diff --git a/lib/libpthread/thread/thr_write.c b/lib/libpthread/thread/thr_write.c index 78940e2ca218..97320317346e 100644 --- a/lib/libpthread/thread/thr_write.c +++ b/lib/libpthread/thread/thr_write.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_write.c,v 1.6 1998/05/25 21:45:50 jb Exp $ + * $Id: uthread_write.c,v 1.7 1998/06/09 23:21:04 jb Exp $ * */ #include <sys/types.h> @@ -46,6 +46,7 @@ write(int fd, const void *buf, size_t nbytes) { int blocking; int status; + int type; ssize_t n; ssize_t num = 0; ssize_t ret; @@ -56,6 +57,17 @@ write(int fd, const void *buf, size_t nbytes) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); diff --git a/lib/libpthread/thread/thr_writev.c b/lib/libpthread/thread/thr_writev.c index 9810aca0d4ef..f5cb7889dd14 100644 --- a/lib/libpthread/thread/thr_writev.c +++ b/lib/libpthread/thread/thr_writev.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_writev.c,v 1.7 1998/05/27 00:44:58 jb Exp $ + * $Id: uthread_writev.c,v 1.8 1998/06/09 23:21:05 jb Exp $ * */ #include <sys/types.h> @@ -48,6 +48,7 @@ writev(int fd, const struct iovec * iov, int iovcnt) { int blocking; int idx = 0; + int type; ssize_t cnt; ssize_t n; ssize_t num = 0; @@ -71,6 +72,17 @@ writev(int fd, const struct iovec * iov, int iovcnt) /* Lock the file descriptor for write: */ if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { + /* Get the read/write mode type: */ + type = _thread_fd_table[fd]->flags & O_ACCMODE; + + /* Check if the file is not open for write: */ + if (type != O_WRONLY && type != O_RDWR) { + /* File is not open for write: */ + errno = EBADF; + _FD_UNLOCK(fd, FD_WRITE); + return (-1); + } + /* Check if file operations are to block */ blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); |
