Welcome to little lamb

Code » limb » release » tree

[release] / src / doc / djbunix.h / sa_read.3.md

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

# NAME

sa_read, sa_readmax - read a file and append its content to a stralloc

# SYNOPSIS

    #include <limb/djbunix.h>

```pre hl
int sa_read(stralloc *<em>sa</em>, int <em>fd</em>)
int sa_readmax(stralloc *<em>sa</em>, int <em>fd</em>, size_t <em>max</em>)
```

# DESCRIPTION

The `sa_read`() function reads the entire content of the file associated with
file descriptor `fd` and appends it into the *stralloc* pointed by `sa`.

The `sa_readmax`() function is similar to `sa_read`() but it will only read up
to `max` bytes.

# RETURN VALUE

On success, the `sa_read`() and `sa_readmax`() functions return 1. Otherwise
they return 0 and set `errno` to indicate the error.

# ERRORS

The `sa_read`() and `sa_readmax`() functions may fail and set `errno` for
any of the errors described for [fd_read](3) and [stralloc_readyplus](3).

The `sa_readmax`() function may also fail if :

: *ENOBUFS*
:: The file is larger than `max` bytes.