Welcome to little lamb

Code » limb » master » tree

[master] / src / doc / buffer.h / buffer_init.3.md

% limb manual
% buffer_init(3)
% limb 0.1.0
% 2023-07-24

# NAME

buffer_init, buffer_read, buffer_write - initialize an I/O buffer

# SYNOPSIS

    #include <limb/buffer.h>

```pre hl
int buffer_init(buffer *<em>buf</em>, iov_func *<em>opfn</em>, int <em>fd</em>, char *<em>mem</em>, size_t <em>len</em>)

ssize_t buffer_read(int <em>fd</em>, struct iovec *<em>v</em>, unsigned int <em>n</em>)
ssize_t buffer_write(int <em>fd</em>, struct iovec *<em>v</em>, unsigned int <em>n</em>)
```

# DESCRIPTION

The `buffer_init`() function initializes the buffer pointed by `buf`, to use the
function `opfn` as its operational function with the file descriptor `fd`. It
will use the memory pointed by `mem` of length `len` as its internal buffer.

The `buffer_read`() macro is a function that can be used to initialize a reading
buffer, that is a buffer used to read from its associated file descriptor.

The `buffer_write`() macro is a function that can be used to initialize a
writing buffer, that is a buffer used to write to its associated file
descriptor.

# RETURN VALUE

The `buffer_init`() function returns 1 on success. Otherwise it returns 0 and
set `errno` to indicate the error.

The `buffer_read`() and `buffer_write`() functions return the amount of data
read or written, respectively, from the file descriptor `fd`, using the memory
as described by the vectors `v` of length `n`, on success. Otherwise they return
-1 and set `errno` to indicate the error.

# ERRORS

The `buffer_init`() function may fail if :

: *EINVAL*
:: The length of memory `len` is too small.

The `buffer_read`() and `buffer_write`() function may fail for any of the errors
described for [fd_readv](3) and [fd_writev](3) respectively.