diff options
Diffstat (limited to 'lib/libpthread/thread/thr_write.c')
-rw-r--r-- | lib/libpthread/thread/thr_write.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/libpthread/thread/thr_write.c b/lib/libpthread/thread/thr_write.c index 78940e2..9732031 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); |