limb 0.2.0

2024-01-09

buffer_put(3)
limb manual
buffer_put(3)

NAME

buffer_put, buffer_putv, buffer_puts, buffer_putall, buffer_putvall, buffer_putsall, buffer_putnoflush, buffer_putvnoflush, buffer_putsnoflush, buffer_putflush, buffer_putvflush, buffer_putsflush, buffer_putallflush, buffer_putvallflush, buffer_putsallflush, buffer_putallnoflush, buffer_putvallnoflush, buffer_putsallnoflush - write data into a writing I/O buffer

SYNOPSIS

#include <limb/buffer.h>
ssize_t buffer_put(buffer *buf, const char *data, size_t dlen)
ssize_t buffer_putv(buffer *buf, const struct iovec *v, unsigned vlen)
ssize_t buffer_puts(buffer *buf, const char *str)

int buffer_putall(buffer *buf, const char *data, size_t dlen, size_t *written)
int buffer_putvall(buffer *buf, const struct iovec *v, unsigned vlen, size_t *written)
int buffer_putsall(buffer *buf, const char *str, size_t *written)

size_t buffer_putnoflush(buffer *buf, const char *data, size_t dlen)
size_t buffer_putvnoflush(buffer *buf, const struct iovec *v, unsigned vlen)
size_t buffer_putsnoflush (buffer *buf, const char *str)

ssize_t buffer_putflush(buffer *buf, const char *data, size_t dlen)
ssize_t buffer_putvflush(buffer *buf, const struct iovec *v, unsigned vlen)
ssize_t buffer_putsflush(buffer *buf, const char *str)

int buffer_putallflush(buffer *buf, const char *data, size_t dlen, size_t *written)
int buffer_putvallflush(buffer *buf, const struct iovec *v, unsigned vlen, size_t *written)
int buffer_putsallflush(buffer *buf, const char *str, size_t *written)

int buffer_putallnoflush(buffer *buf, const char *data, size_t dlen)
int buffer_putvallnoflush(buffer *buf, const struct iovec *v, unsigned vlen)
int buffer_putsallnoflush(buffer *buf, const char *str)

DESCRIPTION

The buffer_put() function will write data pointed by data of length dlen into the buffer pointed by buf. Said data are simply copied into the buffer's internal memory. If the buffer gets full before all data can been copied, it will be flushed in order to place the remaining data into its internal memory.

The buffer_putv() function is similar to buffer_put() only reading data from the array of vectors pointed by v of length vlen.

The buffer_puts() function is similar to buffer_put() only reading the memory pointed by str, which must be NUL-terminated.

NUL-terminated strings

Note that for the buffer_puts*() family of functions, the data put into the buffer is only that up to - and thus excluding - the NUL-terminating byte.

The buffer_putall() function is similar to buffer_put(), except that it will put into the buffer the data starting at offset whose value is pointed by written (usually 0), updating it as it writes data into the buffer. As a result, the size written into the buffer will have been added into the value pointed by written.

The buffer_putvall() function is similar to buffer_putall() only reading data from the array of vectors pointed by v of length vlen. Note that as expected, the value pointed by written must the be offset (in bytes) into the data represented by v.

The buffer_putsall() function is similar to buffer_putall() only reading the memory pointed by str, which must be NUL-terminated.

The buffer_putnoflush() macro is similar to buffer_put() except that it will not flush the buffer, returning the size of data actually placed into the buffer - which may or may not be the full dlen size.

The buffer_putvnoflush() macro is similar to buffer_putnoflush() only reading data from the array of vectors pointed by v of length vlen.

The buffer_putsnoflush() function is similar to buffer_putnoflush() only reading the memory pointed by str, which must be NUL-terminated.

The buffer_putflush() function is similar to buffer_put() but will always flush the buffer afterwards, leaving it - on success - empty.

The buffer_putvflush() function is similar to buffer_putflush() only reading data from the array of vectors pointed by v of length vlen.

The buffer_putsflush() function is similar to buffer_putflush() only reading the memory pointed by str, which must be NUL-terminated.

The buffer_putallflush() macro is similar to buffer_putall() but will always flush the buffer afterwards.

The buffer_putvallflush() macro is similar to buffer_putallflush() only reading data from the array of vectors pointed by v of length vlen.

The buffer_putsallflush() function is similar to buffer_putallflush() only reading the memory pointed by str, which must be NUL-terminated.

The buffer_putallnoflush() function is similar to buffer_putnoflush() except that if the entirety of the data cannot be placed into the buffer, it fails without placing any data into it.

The buffer_putvallnoflush() function is similar to buffer_putallnoflush() only reading data from the array of vectors pointed by v of length vlen.

The buffer_putsallnoflush() function is similar to buffer_putallnoflush() only reading the memory pointed by str, which must be NUL-terminated.

RETURN VALUE

The buffer_put(), buffer_putv(), buffer_puts(), buffer_putflush(), buffer_putvflush() and buffer_putsflush() functions return the size of data placed into the buffer on success. Otherwise, they return -1 and set errno to indicate the error.

The buffer_putnoflush(), buffer_putvnoflush() and buffer_putsnoflush() functions return the size of data placed into the buffer. They cannot fail, although the size returned might be less than the full data size if the buffer lacked space in its internal memory.

The buffer_put{,v,s}all* family of functions all return 1 on success. Otherwise they return 0 and set errno to indicate the error.

ERRORS

These functions may fail and set errno for any of the errors specified for buffer_flush(3).

The buffer_put{,v,s}all* family of functions may also fail if :

EINVAL

The value pointed by written is more than the full data size.

SEE ALSO

buffer_putmsg(3), buffer_putesc(3), buffer_puthex(3), buffer_putbase32(3), buffer_putbase64(3), buffer_puthdr(3), buffer_patrim_put(3)

limb 0.1.0
2023-07-24
buffer_put(3)