libwget-io(3) | wget2 | libwget-io(3) |
libwget-io - I/O helper routines
ssize_t wget_fdgetline (char **buf, size_t *bufsize, int
fd)
ssize_t wget_getline (char **buf, size_t *bufsize, FILE *fp)
int wget_ready_2_transfer (int fd, int timeout, int mode)
int wget_ready_2_read (int fd, int timeout)
int wget_ready_2_write (int fd, int timeout)
char * wget_read_file (const char *fname, size_t *size)
int wget_update_file (const char *fname, wget_update_load_t load_func,
wget_update_load_t save_func, void *context)
int wget_truncate (const char *path, off_t length)
Some general I/O helper functions that could be handy for developers.
Parameters
Returns
Behaves identically as wget_getline(), but uses a file descriptor instead of a stream.
Parameters
Returns
This function will read a line from the open file handle fp. This function reads input characters until either a newline character (\\n) is found or EOF is reached. A block of memory large enough to hold the read line will be implicitly allocated by the function, and its address placed at the pointer pointed to by buf. The length of the aforementioned memory block will be stored in the variable pointed at by bufsize.
The caller is not expected to allocate memory as that will be automatically done by wget_getline(), but it is responsibility of the caller free the memory allocated by a previous invocation of this function. The caller is also responsible for opening and closing the file to read from.
Subsequent calls to wget_getline() that use the same block of memory allocated by previous calls (that is, the caller did not free the buffer returned by a previous call to wget_getline()) will try to reuse as much as possible from the available memory. The block of memory allocated by wget_getline() may be larger than the length of the line read, and might even contain additional lines in it. When wget_getline() returns, the contents of the buffer (pointed at by buf) are guaranteed to start with the first character of the last line read, and such line is also guaranteed to end with a NULL termination character (\0). The length of the last read line will be returned by wget_getline(), whereas the actual length of the buffer will be placed in the variable pointed at by bufsize. The newline character (\\n) will not be included in the last read line.
Parameters
Returns
Wait for a file descriptor to become ready to read or write.
A timeout value of 0 means the function returns
immediately.
A timeout value of -1 means infinite timeout.
Parameters
Returns
Wait for a file descriptor to become ready to read.
A timeout value of 0 means the function returns
immediately.
A timeout value of -1 means infinite timeout.
Parameters
Returns
Wait for a file descriptor to become ready to write.
A timeout value of 0 means the function returns
immediately.
A timeout value of -1 means infinite timeout.
Parameters
Returns
Reads the content of a file, or from STDIN. When reading from STDIN, the behavior is the same as for regular files: input is read until an EOF character is found.
Memory will be accordingly allocated by wget_read_file() and a pointer to it returned when the read finishes, but the caller is responsible for freeing that memory. The length of the allocated block of memory, which is guaranteed to be the same as the length of the data read, will be placed in the variable pointed at by size.
The read data is guaranteed to be appended a NUL termination character (\0).
Parameters
Returns
This function updates the file named fname atomically. It lets
two caller-provided functions do the actual updating. A lock file is created
first under /tmp to ensure exclusive access to the file. Other processes
attempting to call wget_update_file() with the same fname
parameter will block until the current calling process has finished (that
is, until wget_update_file() has returned).
Then, the file is opened with read access first, and the load_func
function is called. When it returns, the file is closed and opened again
with write access, and the save_func function is called. Both
callback functions are passed the context data context, and a stream
descriptor for the file. If either function load_func or
save_func returns a non-zero value, wget_update_file()
closes the file and returns -1, performing no further actions.
Parameters
Returns
Set path to a size of exactly length bytes.
If the file was previously larger, the extra data is lost. If the file was previously shorter, extra zero bytes are added.
On POSIX, this is a wrapper around ftruncate() (see 'man ftruncate' for details).
Generated automatically by Doxygen for wget2 from the source code.
Tue Jan 26 2021 | Version 1.99.1 |