readdir_r - Man Page

read a directory

Library

Standard C library (libc, -lc)

Synopsis

#include <dirent.h>

[[deprecated]] int readdir_r(DIR *restrict dirp,
                             struct dirent *restrict entry,
                             struct dirent **restrict result);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

readdir_r():

    _POSIX_C_SOURCE
        || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

Description

This function is deprecated; use readdir(3) instead.

The readdir_r() function was invented as a reentrant version of readdir(3). It reads the next directory entry from the directory stream dirp, and returns it in the caller-allocated buffer pointed to by entry. For details of the dirent structure, see readdir(3).

A pointer to the returned buffer is placed in *result; if the end of the directory stream was encountered, then NULL is instead returned in *result.

It is recommended that applications use readdir(3) instead of readdir_r(). Furthermore, since glibc 2.24, glibc deprecates readdir_r(). The reasons are as follows:

Return Value

The readdir_r() function returns 0 on success. On error, it returns a positive error number (listed under Errors). If the end of the directory stream is reached, readdir_r() returns 0, and returns NULL in *result.

Errors

EBADF

Invalid directory stream descriptor dirp.

ENAMETOOLONG

A directory entry whose name was too long to be read was encountered.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
readdir_r()Thread safetyMT-Safe

Standards

POSIX.1-2008.

History

POSIX.1-2001.

See Also

readdir(3)

Referenced By

readdir(3).

2024-05-02 Linux man-pages 6.9.1