libjapi  0.3.2
Universal JSON API Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
rw_n.h File Reference

Read or write a fixed number of bytes. More...

#include <stdint.h>
Include dependency graph for rw_n.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int read_n (int fd, void *buf, size_t count)
 Read a fixed number of bytes from a file descriptor. More...
 
int write_n (int fd, const void *buf, size_t count)
 Write a fixed number of bytes to a file descriptor. More...
 

Detailed Description

Read or write a fixed number of bytes.

Author
Christopher Stender
Date
2018-02-15
Version
0.1

Use read_n() to read or write_n() to write a fixed number of bytes from or to a file descriptor.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Function Documentation

int read_n ( int  fd,
void *  buf,
size_t  count 
)

Read a fixed number of bytes from a file descriptor.

read_n reads count bytes from a file descriptor fd into the buffer starting at buf. If the underlying read returns with less than count bytes read, read_n() calls read() again until all bytes are read or an error or EOF occurs.

Parameters
fdFile descriptor
bufPointer to the target buffer
countNumber of bytes to copy
Returns
On success, the number of bytes read is returned (zero indicates end of file). On error, -1 is returned, and errno is set appropriately.
int write_n ( int  fd,
const void *  buf,
size_t  count 
)

Write a fixed number of bytes to a file descriptor.

write_n writes count bytes from the buffer buf to the file descriptor fd. If the underlying write() returns with less than count bytes written, write_n() calls write() again until all bytes are written or an error occurs.

Parameters
fdFile descriptor
bufPointer to the target buffer
countNumber of bytes to copy
Returns
On success, the number of bytes written is returned. On error, -1 is returned, and errno is set appropriately.

Referenced by japi_pushsrv_sendmsg(), and japi_start_server().