limb 0.2.0

2024-01-09

buffer_getuptoc(3)
limb manual
buffer_getuptoc(3)

NAME

buffer_getuptoc - read data from buffer up to a given character

SYNOPSIS

#include <limb/buffer.h>
int buffer_getuptoc(buffer *buf, char *dst, size_t len, char c, size_t *got)

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).

limb 0.1.0
2023-07-24
buffer_getuptoc(3)