thr_write.c (50476) | thr_write.c (53812) |
---|---|
1/* 2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/lib/libkse/thread/thr_write.c 50476 1999-08-28 00:22:10Z peter $ | 32 * $FreeBSD: head/lib/libkse/thread/thr_write.c 53812 1999-11-28 05:38:13Z alfred $ |
33 * 34 */ 35#include <sys/types.h> 36#include <sys/fcntl.h> 37#include <sys/uio.h> 38#include <errno.h> 39#include <unistd.h> 40#ifdef _THREAD_SAFE --- 4 unchanged lines hidden (view full) --- 45write(int fd, const void *buf, size_t nbytes) 46{ 47 int blocking; 48 int type; 49 ssize_t n; 50 ssize_t num = 0; 51 ssize_t ret; 52 | 33 * 34 */ 35#include <sys/types.h> 36#include <sys/fcntl.h> 37#include <sys/uio.h> 38#include <errno.h> 39#include <unistd.h> 40#ifdef _THREAD_SAFE --- 4 unchanged lines hidden (view full) --- 45write(int fd, const void *buf, size_t nbytes) 46{ 47 int blocking; 48 int type; 49 ssize_t n; 50 ssize_t num = 0; 51 ssize_t ret; 52 |
53 _thread_enter_cancellation_point(); |
|
53 /* POSIX says to do just this: */ | 54 /* POSIX says to do just this: */ |
54 if (nbytes == 0) | 55 if (nbytes == 0) { 56 _thread_leave_cancellation_point(); |
55 return (0); | 57 return (0); |
58 } |
|
56 57 /* Lock the file descriptor for write: */ 58 if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { 59 /* Get the read/write mode type: */ 60 type = _thread_fd_table[fd]->flags & O_ACCMODE; 61 62 /* Check if the file is not open for write: */ 63 if (type != O_WRONLY && type != O_RDWR) { 64 /* File is not open for write: */ 65 errno = EBADF; 66 _FD_UNLOCK(fd, FD_WRITE); | 59 60 /* Lock the file descriptor for write: */ 61 if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { 62 /* Get the read/write mode type: */ 63 type = _thread_fd_table[fd]->flags & O_ACCMODE; 64 65 /* Check if the file is not open for write: */ 66 if (type != O_WRONLY && type != O_RDWR) { 67 /* File is not open for write: */ 68 errno = EBADF; 69 _FD_UNLOCK(fd, FD_WRITE); |
67 return (-1); | 70 _thread_leave_cancellation_point(); 71 return (-1); |
68 } 69 70 /* Check if file operations are to block */ 71 blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); 72 73 /* 74 * Loop while no error occurs and until the expected number 75 * of bytes are written if performing a blocking write: --- 48 unchanged lines hidden (view full) --- 124 125 /* Check if the write has completed: */ 126 } else if (num >= nbytes) 127 /* Return the number of bytes written: */ 128 ret = num; 129 } 130 _FD_UNLOCK(fd, FD_RDWR); 131 } | 72 } 73 74 /* Check if file operations are to block */ 75 blocking = ((_thread_fd_table[fd]->flags & O_NONBLOCK) == 0); 76 77 /* 78 * Loop while no error occurs and until the expected number 79 * of bytes are written if performing a blocking write: --- 48 unchanged lines hidden (view full) --- 128 129 /* Check if the write has completed: */ 130 } else if (num >= nbytes) 131 /* Return the number of bytes written: */ 132 ret = num; 133 } 134 _FD_UNLOCK(fd, FD_RDWR); 135 } |
136 _thread_leave_cancellation_point(); |
|
132 return (ret); 133} 134#endif | 137 return (ret); 138} 139#endif |