Welcome to little lamb

Code » limb » master » tree

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

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

# NAME

buffer\_puthdr, buffer\_gethdr - write/read file header

# SYNOPSIS

    #include <limb/buffer.h>

```pre hl
ssize_t buffer_puthdr(buffer *<em>buf</em>, u32 <em>magic</em>, u64 <em>ver</em>)
int buffer_gethdr(buffer *<em>buf</em>, u32 *<em>magic</em>, u64 *<em>ver</em>)
```

# DESCRIPTION

The `buffer_puthdr`() function writes into the buffer `buf` the magic `magic` as
a 32bit unsigned integer in big-endian followed by the unsigned integer `ver` in
pack-trimmed form, as described in [u64_pack_trim](3).

Such a combinaison is intended to be used as a file header, used notably for
files containing [patrim](5)-encoded data.

The `buffer_get_hdr`() function reads such an header and places the 32bit magic
number as the value pointed by `magic`, and the version number as the value
pointer by `ver`.

# RETURN VALUE

The `buffer_puthdr`() function returns the number of bytes written into the
buffer on success. Otherwise, it returns -1.

The `buffer_gethdr`() function returns 1 on success, and 0 on failure.

# ERRORS

The `buffer_puthdr`() function may fail and set `errno` for any of the errors
specified for [buffer_putv](3).

The `buffer_gethdr`() function may fail if :

: *EPIPE*
:: Not enough data could be read from the buffer before reaching end-of-file.

It may also fail for any of the error specified for [buffer_get](3) or
[buffer_fill](3).