Welcome to little lamb

Code » limb » release » tree

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

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

# NAME

open_read_closeat, open_read_close, open_saread_closeat, open_saread_close -
open, read & close a file

# SYNOPSIS

    #include <limb/djbunix.h>

```pre hl
ssize_t open_read_closeat(char *<em>dst</em>, size_t <em>dlen</em>, int <em>fd</em>, const char *<em>file</em>)
ssize_t open_read_close(char *<em>dst</em>, size_t <em>dlen</em>, const char *<em>file</em>)

int open_saread_closeat(stralloc *<em>sa</em>, int <em>fd</em>, const char *<em>file</em>)
int open_saread_close(stralloc *<em>sa</em>, const char *<em>file</em>)
```

# DESCRIPTION

The `open_read_closeat`() function will open the file named `file` for reading
in blocking mode. If `file` describes a relative path, it is relative to the
directory associated with the file descriptor `fd`, which may be *AT_FDCWD* to
use the current working directory.

The content of the file will be read and copied into the memory pointed by `dst`
up to a maximum of `dlen` bytes, and the file be closed.

The `open_read_close`() macro is similar to `open_read_closeat`() only relative
paths are relative to the current working directory.

The `open_saread_closeat`() function is to `open_read_closeat`(), except the
entirety of the file will be placed into the *stralloc* pointed by `sa`,
allocating as much memory as needed.

The `open_saread_close`() macro is similar to `open_saread_closeat`() only
relative paths are relative to the current working directory.

# RETURN VALUE

The `open_read_close`() and `open_read_closeat`() functions return the amount of
data read from the file, and written into `dst`, on success. Otherwise they
return -1 and set `errno` to indicate the error.

The `open_saread_close`() and `open_saread_closeat`() functions return 1 on
success. Otherwise they return 0 and set `errno` to indicate the error.

# ERRORS

These functions may fail and set `errno` for the errors described for
[openb_readat](3).

The `open_read_close`() and `open_read_closeat`() functions may also fail if :

: *ENOBUFS*
:: Not enough space available in `dst` to store the entire file.

The `open_read_close`() and `open_read_closeat`() functions may also fail and
set `errno` for the errors described for [allread](3).

The `open_saread_close`() and `open_saread_closeat`() fucntions may also fail
and set `errno` for the errors described for [sa_read](3).