The Hackerlab at `regexps.com`

## VU Utilities

up: libhackerlab next: An Errorless Front-end to the VU File-system Interface prev: Formatted Printing With printfmt

These functions provide higher-level abstractions that capture common ways of using the lower-level VU functions.

Function `vu_file_to_string`

    int vu_file_to_string (int * errn,
                           t_uchar ** buf,
                           size_t * len,
                           int fd);

Read the entire contents of `fd` into a newly allocated string.

If no error occurs, return `0` . The new string is returned in `*buf` ; its length in `*len` .

If an I/O error occurs, return `-1` and fill `*errn` .

If `vu_fstat` is able to report the length of the file, a single call to `vu_read_retry` is used to read its contents. Otherwise, repeated calls to `vu_read_retry` are used.

Function `vu_move_fd`

    int vu_move_fd (int * errn, int fd, int newfd);

Relocate `fd` to `newfd` . `fd` must already be handled by VU.

Thus function performs a `vu_dup` or `vu_dup2`

This is useful when performing file redirections after `fork` and before `exec` .

Function `vu_file_is_directory`

    int vu_file_is_directory (int * errn, t_uchar * name);

Return `1` if `name` names a directory, `0` if not, `-1` on error.

Non-existence of any file called `name` is not an error.

Function `vu_file_is_directory_following`

    int vu_file_is_directory_following (int * errn, t_uchar * name);

Return `1` if `name` names a directory or symlink to a directory, `0` if not, `-1` on error.

Non-existence of any file called `name` is not an error.

libhackerlab: The Hackerlab C Library
The Hackerlab at `regexps.com`