Welcome to little lamb

Code » limb » master » tree

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

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

# NAME

buffer\_getuptoc - read data from buffer up to a given character

# SYNOPSIS

    #include <limb/buffer.h>

```pre hl
int buffer_getuptoc(buffer *<em>buf</em>, char *<em>dst</em>, size_t <em>len</em>, char <em>c</em>, size_t *<em>got</em>)
```

# DESCRIPTION

The `buffer_getuptoc`() function will read data from the buffer `buf` (filling
it if needed) and put the data into memory area pointed to by `dst` up to `len`
bytes, stopping as soon as byte `c` is read.

That is, the buffer will have only been read up to a byte whose value is `c`.
Meaning in case of success, the last byte read from the buffer will be the last
byte put into `dst`, i.e. byte `c`.

The value pointed to by `got` must indicate how much data has already been
filled into `dst` prior (i.e. it will usually be 0), and will be updated as
needed.

In other words, data will be written into `dst` starting at the offset pointed
to by `got`.

! HINT:
! This function can be useful to read user input from *stdin* up to a new line
! (`\n`).

# RETURN VALUE

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

# ERRORS

The `buffer_getuptoc`() function may fail if :

: *EINVAL*
:: The value pointed to by `got` is larger than `len`

: *ENOBUFS*
:: There is no more space in `dst` (i.e. the value pointed to by `got` has
:: reached `len`).

: *EPIPE*
:: End of file has been reached hence the buffer couldn't be filled (anymore).

It can also fail and set `errno` for any of the errors specified for
[buffer_fill](3).