Welcome to little lamb

Code » limb » master » tree

[master] / src / doc / direntry.h / sa_scandirat.3.md

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

# NAME

sa_scandirat, sa_scandir - scan a directory to fill a stralloc

# SYNOPSIS

    #include <fcntl.h> /* AT_FDCWD */
    #include <limb/direntry.h>

```pre hl
typedef ssize_t (*sa_scande) (stralloc *<em>sa</em>, direntry *<em>de</em>, int <em>dirfd</em>, void *<em>ctx</em>)

int sa_scandirat(stralloc *<em>sa</em>, int <em>dirfd</em>, const char *<em>name</em>, sa_scande <em>fn</em>, void *<em>ctx</em>)
int sa_scandir(stralloc *<em>sa</em>, const char *<em>name</em>, sa_scande <em>fn</em>, void *<em>ctx</em>)
```

# DESCRIPTION

The `sa_scandirat`() function scans the directory `name` calling the function
`fn` on each of its directory entry, save for `.` and `..` which are ignored.
Said function shall add relevant information regarding the directory entry
pointed by `de` into the *stralloc* pointed by `sa` and return 1 on success. It
can also return 0 if nothing was added, e.g. the file/entry was simply ignored.
In case of failure it must return -1 and set `errno` to indicate the error.

If `name` describes a relative path, it is relative to the directory associated
with the file descriptor `dirfd`, which may be *AT_FDCWD* to use the current
working directory.

The `sa_scandir`() macro is similar, except when `name` describes a relative
path, in which case it is relative to the current working directory.

# RETURN VALUE

These functions returns the number of entries for which data was added into `sa`
on success. Otherwise it returns -1 and sets `errno` to indicate the error.

# ERRORS

These functions may fail and set `errno` for the error described for
[opendirat](3), [readdir](3), as well as those set by the function `fn`.