__opendir2() — Open a directory

Standards

Standards / Extensions C or C++ Dependencies

z/OS® UNIX

both OS/390 V2R6

Format

#define _OPEN_SYS_DIR_EXT
#include <dirent.h>

DIR *__opendir2(const char *dirname, size_t bufsize);

General description

Opens a directory so that it can be read with readdir() or __readdir2(). The first readdir() or __readdir2() call reads the first entry in the directory.

dirname is a string giving the name of the directory you want to open. bufsize is the size (in bytes) of the internal work buffer used by readdir() or __readdir2() to hold directory entries. The larger the buffer, the less overhead there will be when reading through large numbers of directory entries. This buffer will exist until the directory is closed. If the specified buffer size is too small, it is ignored. A minimum-size buffer is used instead.

__opendir2() is the same as opendir(), except that the buffer size can be specified as a parameter.

Returned value

If successful, __opendir2() returns a pointer to a DIR object. This object describes the directory and is used in subsequent operations on the directory, in the same way that FILE objects are used in file I/O operations.

If unsuccessful, __opendir2() returns a NULL pointer and sets errno to one of the following values:
Error Code
Description
EACCES
The process does not have permission to search some component of dirname, or it does not have read permission on the directory itself.
ELOOP
A loop exists in the symbolic links. This error is issued if more than POSIX_SYMLOOP (defined in the limits.h header file) symbolic links are encountered during resolution of the dirname argument.
EMFILE
The process has too many other file descriptors already open.
ENAMETOOLONG
dirname is longer than PATH_MAX characters, or some component of dirname is longer than NAME_MAX characters while _POSIX_NO_TRUNC is in effect. For symbolic links, the length of the pathname string substituted for a symbolic link exceeds PATH_MAX. The PATH_MAX and NAME_MAX values can be determined using pathconf().
ENFILE
The entire system has too many other file descriptors already open.
ENOENT
The directory dirname does not exist.
ENOMEM
There is not enough storage available to open the directory using a buffer that is length bufsize bytes long.
ENOTDIR
Some component of the dirname pathname is not a directory.

Related information