Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

opendir(3c) [opensolaris man page]

opendir(3C)						   Standard C Library Functions 					       opendir(3C)

NAME
opendir, fdopendir - open directory SYNOPSIS
#include <sys/types.h> #include <dirent.h> DIR *opendir(const char *dirname); DIR *fdopendir(int fildes); DESCRIPTION
The opendir() function opens a directory stream corresponding to the directory named by the dirname argument. The fdopendir() function opens a directory stream for the directory file descriptor fildes. The directory file descriptor should not be used or closed following a successful function call, as this might cause undefined results from future operations on the directory stream obtained from the call. Use closedir(3C) to close a directory stream. The directory stream is positioned at the first entry. If the type DIR is implemented using a file descriptor, applications will only be able to open up to a total of {OPEN_MAX} files and directories. A successful call to any of the exec functions will close any directory streams that are open in the calling process. See exec(2). RETURN VALUES
Upon successful completion, opendir() and fdopendir() return a pointer to an object of type DIR. Otherwise, a null pointer is returned and errno is set to indicate the error. ERRORS
The opendir() function will fail if: EACCES Search permission is denied for the component of the path prefix of dirname or read permission is denied for dirname. ELOOP Too many symbolic links were encountered in resolving path. ENAMETOOLONG The length of the dirname argument exceeds {PATH_MAX}, or a path name component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect. ENOENT A component of dirname does not name an existing directory or dirname is an empty string. ENOTDIR A component of dirname is not a directory. The fdopendir() function will fail if: ENOTDIR The file descriptor fildes does not reference a directory. The opendir() function may fail if: EMFILE There are {OPEN_MAX} file descriptors currently open in the calling process. ENAMETOOLONG Pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX. ENFILE Too many files are currently open on the system. USAGE
The opendir() and fdopendir() functions should be used in conjunction with readdir(3C), closedir(3C) and rewinddir(3C) to examine the con- tents of the directory (see the EXAMPLES section in readdir(3C)). This method is recommended for portability. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |opendir() is Standard; | | |fdopendir() is Evolving | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
lstat(2), symlink(2), closedir(3C), readdir(3C), rewinddir(3C), scandir(3C), attributes(5) SunOS 5.11 26 Jun 2007 opendir(3C)

Check Out this Related Man Page

OPENDIR(3)						     Linux Programmer's Manual							OPENDIR(3)

NAME
opendir, fdopendir - open a directory SYNOPSIS
#include <sys/types.h> #include <dirent.h> DIR *opendir(const char *name); DIR *fdopendir(int fd); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): fdopendir(): Since glibc 2.10: _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE DESCRIPTION
The opendir() function opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream. The stream is positioned at the first entry in the directory. The fdopendir() function is like opendir(), but returns a directory stream for the directory referred to by the open file descriptor fd. After a successful call to fdopendir(), fd is used internally by the implementation, and should not otherwise be used by the application. RETURN VALUE
The opendir() and fdopendir() functions return a pointer to the directory stream. On error, NULL is returned, and errno is set appropri- ately. ERRORS
EACCES Permission denied. EBADF fd is not a valid file descriptor opened for reading. EMFILE Too many file descriptors in use by process. ENFILE Too many files are currently open in the system. ENOENT Directory does not exist, or name is an empty string. ENOMEM Insufficient memory to complete the operation. ENOTDIR name is not a directory. VERSIONS
fdopendir() is available in glibc since version 2.4. CONFORMING TO
opendir() is present on SVr4, 4.3BSD, and specified in POSIX.1-2001. fdopendir() is specified in POSIX.1-2008. NOTES
The underlying file descriptor of the directory stream can be obtained using dirfd(3). The opendir() function sets the close-on-exec flag for the file descriptor underlying the DIR *. The fdopendir() function leaves the set- ting of the close-on-exec flag unchanged for the file descriptor, fd. POSIX.1-200x leaves it unspecified whether a successful call to fdopendir() will set the close-on-exec flag for the file descriptor, fd. SEE ALSO
open(2), closedir(3), dirfd(3), readdir(3), rewinddir(3), scandir(3), seekdir(3), telldir(3) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2010-06-20 OPENDIR(3)
Man Page