Welcome to little lamb

Code » limb » master » tree

[master] / src / doc / buffer.h / buffer.h.0.md

% limb manual
% buffer.h(0)
% limb 0.1.0
% 2023-07-24

# NAME

buffer.h - I/O buffer interface

# SYNOPSIS

    #include <limb/buffer.h>

# DESCRIPTION

This header defines required functions to performed buffered I/O operations.

<inc skalibs.md>

## Types

The following types are defined :

: *buffer*
:: An opaque structure representing an I/O buffer.

## Constants

The following constants are defined :

: *BUFFER_ZERO*
:: Value to initialize a stack-allocated *buffer* to.

: *BUFFER_INSIZE*, *BUFFER_OUTSIZE*, *BUFFER_ERRSIZE*, *BUFFER_INSIZE_SMALL*,
: *BUFFER_OUTSIZE_SMALL*
:: Buffer sizes of *buffer_0*, *buffer_1*, *buffer_2*, *buffer_0small*, and
:: *buffer_1small* respectively.

: *PUTMSG_FLUSH*, *PUTMSG_TOGGLE_ESC*, *PUTMSG_ESC*, *PUTMSG_UINT_NEXT*,
: *PUTMSG_INT_NEX*, *PUTMSG_ERR_NEXT*, *PUTMSG_LEN_NEXT*, *PUTMSG_HEX_NEXT*,
: *PUTMSG_DUMP_NEXT*, *ESC*
:: Can be used as a string given to [buffer_putmsg](3) with a special meaning.

## Macros

The following macros are defined :

: *BUFFER_INIT(`fn`, `fd`, `buf`, `len`)*
:: Value to initialize a statck-allocated buffer to, set to use function `fn`
:: with file descriptor `fd` and memory pointed by `buf` of length `len` bytes

: *PUTMSG_UINT(`n`)*, *PUTMSG_INT(`n`)*, *PUTMSG_ERR(`n`)*,
: *PUTMSG_LEN(`data`,`dlen`)*, *PUTMSG_HEX(`data`,`dlen`)*,
: *PUTMSG_DUMP(`data`,`dlen`)*
: *PMUINT(`n`)*, *PMINT(`n`)*, *PMERR(`n`)*, *PMLEN(`data`,`dlen`)*,
: *PMHEX(`data`,`dlen`)*, *PMDMP(`data`,`dlen`)*
:: Can be used for special processing to [buffer_putmsg](3).

## Objects

The following objects are defined :

: *buffer_0*
:: A reading *buffer* connected to fd 0, aka /stdin/

: *buffer_1*
:: A writing *buffer* connected to fd 1, aka /stdout/

: *buffer_2*
:: A writing *buffer* connected to fd 2, akak /stderr/

: *buffer_0small*
:: Similar to *buffer_0* but with a smaller buffer size. Note that you should
:: only use either one or the other, but never mix them both.

: *buffer_1small*
:: Similar to *buffer_1* but with a smaller buffer size. Note that you should
:: only use either one or the other, but never mix them both.

: *buffer_0f1*
:: Similar to *buffer_0* but will first try to flush *buffer_1* and only then
:: attempt to read from /stdin/ - A failure to flush *buffer_1* will cause a
:: failure to fill *buffer_0f1* without having attempted to read from its file
:: descriptor.
:: Note that you should only ever use a single buffer per file descriptor.

## Functions

The following functions/macros are defined :

: [buffer_init](3)
:: Initialize a *buffer*.

: [buffer_read](3)
:: Operational function to initialize a reading *buffer*.

: [buffer_write](3)
:: Operational function to initialize a write *buffer*.

### Writing

: [buffer_flush](3)
:: Flush a *buffer*.

: [buffer_patrim_put](3)
:: To write given data in [patrim](5)-encoded format.

: [buffer_patrim_putv](3)
:: Similar to [buffer_patrim_put](3) put using vectors for actual data.

: [buffer_put](3)
:: Write data of specified length to a *buffer*, flushing it if needed.

: [buffer_putall](3)
:: Similar to [buffer_put](3) but with a different interface.

: [buffer_putallflush](3)
:: Write data of specified length to a *buffer* and flush it.

: [buffer_putallnoflush](3)
:: Write data of specified length to a *buffer* without flushing it.

: [buffer_putbase32](3)
:: To write given data encoded in base32.

: [buffer_putbase64](3)
:: To write given data encoded in base64.

: [buffer_putescall](3)
:: To write given data from a specified offset whilst escaping characters as
:: needed.

: [buffer_putesc](3)
:: Similar to [buffer_putescall](3) but without a starting offset into given
:: data.

: [buffer_putescs](3)
:: Similar but for a NUL-terminated string.

: [buffer_putflush](3)
:: Write data of specified length to a *buffer* and flush it.

: [buffer_puthdr](3)
:: To write a file header of 32bit big-endian magic & pack-trimmed version.

: [buffer_puthex](3)
:: To write given data as hexadecimal dump.

: [buffer_putmsg](3)
:: To write a message, given as an array of NUL-terminated strings.

: [buffer_putnoflush](3)
:: Write data of specified length to a *buffer* without flushing it.

: [buffer_putv](3)
:: Similar to [buffer_put](3) but with vectors.

: [buffer_putvall](3)
:: Similar to [buffer_putall](3) but with vectors.

: [buffer_putvallflush](3)
:: Similar to [buffer_putallflush](3) but with vectors.

: [buffer_putvallnoflush](3)
:: Similar to [buffer_putallnoflush](3) but with vectors.

: [buffer_putvflush](3)
:: Similar to [buffer_putflush](3) but with vectors.

: [buffer_putvnoflush](3)
:: Similar to [buffer_putnoflush](3) but with vectors.

: [buffer_puts](3)
:: Similar to [buffer_put](3) but with a NUL-terminated string.

: [buffer_putsall](3)
:: Similar to [buffer_putall](3) put with a NUL-terminated string.

: [buffer_putsallflush](3)
:: Similar to [buffer_putallflush](3) but with a NUL-terminated string.

: [buffer_putsallnoflush](3)
:: Similar to [buffer_putallnoflush](3) but with a NUL-terminated string.

: [buffer_putsflush](3)
:: Similar to [buffer_putflush](3) but with a NUL-terminated string.

: [buffer_putsnoflush](3)
:: Similar to [buffer_putnofhlush](3) but with a NUL-terminated string.

: [buffer_unput](3)
:: Removes data from the buffer.

: [buffer_wpeek](3)
:: Peek vectors of available space to write into a *buffer*.

: [buffer_wseek](3)
:: Seek into a writing *buffer*.


### Reading

: [buffer_fill](3)
:: Fill a *buffer*.

: [buffer_get](3)
:: Get data from a *buffer*, filling it if needed.

: [buffer_getall](3)
:: Similar to [buffer_get](3) but with a different interface.

: [buffer_getallnofill](3)
:: Get data from a *buffer* without filling it.

: [buffer_gethdr](3)
:: Get a file header of 32bit big-endian magic & pack-trimmed version from a
:: *buffer*.

: [buffer_getnofill](3)
:: Get data from a *buffer* without filling it.

: [buffer_getuptoc](3)
:: To read data from buffer up to a given character.

: [buffer_getv](3)
:: Similar to [buffer_get](3) but with vectors.

: [buffer_getvall](3)
:: Similar to [buffer_getall](3) but with vectors.

: [buffer_getvallnofill](3)
:: Similar to [buffer_getallnofill](3) but with vectors.

: [buffer_getvnofill](3)
:: Similar to [buffer_butnofill](3) but with vectors.

: [buffer_patrim_get](3)
:: To read [patrim](5)-encoded data.

: [buffer_rpeek](3)
:: Peek vectors of available data into a *buffer*.

: [buffer_rseek](3)
:: Seek into a reading *buffer*.

: [buffer_unget](3)
:: "Restores" data into a *buffer*.


### Utility

: [buffer_len](3)
:: Returns the total length of a *buffer*.

: [buffer_getlen](3)
:: Similar to [buffer_len](3).

: [buffer_available](3)
:: Returns available space in a *buffer*.

: [buffer_isempty](3)
:: Returns whether or not a *buffer* is empty.

: [buffer_isfull](3)
:: Returns whether or not a *buffer* is full.

: [buffer_fd](3)
:: Returns the file descriptor associated with a *buffer*.

: [buffer_getfd](3)
:: Simimar to [buffer_fd](3).

: [buffer_isreadable](3)
:: Returns whether or not a *buffer* can be filled, i.e. is not full.

: [buffer_iswritable](3)
:: Returns whether or not a *buffer* can be flushed, i.e. is not empty.