Adds OS internal function nx_write() which is functionally equivalent to write() except that it does not set the errno variable and do not cause cancellation points.

This commit is contained in:
Gregory Nutt
2017-10-11 10:18:30 -06:00
parent af072d52bc
commit a00d8e16a1
14 changed files with 212 additions and 128 deletions
+34 -5
View File
@@ -84,12 +84,14 @@
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
# define _NX_WRITE(f,b,s) nx_write(s,b,s)
# define _NX_ERRNO(r) (-(r))
# define _NX_ERRVAL(r) (r)
# define _NX_GETERRNO(r) (-(r))
# define _NX_SETERRNO(r) set_errno(-(r))
# define _NX_GETERRVAL(r) (r)
#else
# define _NX_WRITE(f,b,s) rite(s,b,s)
# define _NX_ERRNO(r) errno
# define _NX_ERRVAL(r) (-errno)
# define _NX_WRITE(f,b,s) write(s,b,s)
# define _NX_GETERRNO(r) errno
# define _NX_SETERRNO(r)
# define _NX_GETERRVAL(r) (-errno)
#endif
/* Stream flags for the fs_flags field of in struct file_struct */
@@ -935,6 +937,33 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes);
ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes);
#endif
/****************************************************************************
* Name: nx_write
*
* Description:
* nx_write() writes up to nytes bytes to the file referenced by the file
* descriptor fd from the buffer starting at buf. nx_write() is an
* internal OS function. It is functionally equivalent to write() except
* that:
*
* - It does not modify the errno variable, and
* - It is not a cancellation point.
*
* Input Parameters:
* fd - file descriptor (or socket descriptor) to write to
* buf - Data to write
* nbytes - Length of data to write
*
* Returned Value:
* On success, the number of bytes written are returned (zero indicates
* nothing was written). On any failure, a negated errno value is returned
* (see comments withwrite() for a description of the appropriate errno
* values).
*
****************************************************************************/
ssize_t nx_write(int fd, FAR const void *buf, size_t nbytes);
/****************************************************************************
* Name: file_pread
*
+4 -4
View File
@@ -76,14 +76,14 @@
# define _NX_SEND(s,b,l,f) nx_send(s,b,l,f)
# define _NX_RECV(s,b,l,f) nx_recv(s,b,l,f)
# define _NX_RECVFROM(s,b,l,f,a,n) nx_recvfrom(s,b,l,f,a,n)
# define _NX_ERRNO(r) (-(r))
# define _NX_ERRVAL(r) (r)
# define _NX_GETERRNO(r) (-(r))
# define _NX_GETERRVAL(r) (r)
#else
# define _NX_SEND(s,b,l,f) send(s,b,l,f)
# define _NX_RECV(s,b,l,f) recv(s,b,l,f)
# define _NX_RECVFROM(s,b,l,f,a,n) recvfrom(s,b,l,f,a,n)
# define _NX_ERRNO(r) errno
# define _NX_ERRVAL(r) (-errno)
# define _NX_GETERRNO(r) errno
# define _NX_GETERRVAL(r) (-errno)
#endif
/* Socket descriptors are the index into the TCB sockets list, offset by the