directory.3c (2010 09)
d
directory(3C) directory(3C)
returns a NULL pointer and sets errno
to indicate the error.
readdir_r() upon successful completion returns a 0. On successful return, the pointer returned at
result has the same value as the argument
entry. Upon reaching end of the
directory stream,
result has the value NULL. An error number is returned upon
error.
telldir() upon successful completion, returns a long value indicating the current position in the
directory. Otherwise it returns -1 and sets
errno to indicate the error.
seekdir() does not return any value, but if an error is encountered,
errno is set to indicate the
error.
closedir() upon successful completion, returns a value of
0. Otherwise, it returns a value of -1
and sets errno to indicate the error.
ERRORS
opendir() fails if any of the following conditions are encountered:
[EACCES] Search permission is denied for a component of dirname , or read permission is
denied for dirname .
[EFAULT] dirname points outside the allocated address space of the process. The reliable
detection of this error is implementation dependent.
[ELOOP] Too many symbolic links were encountered in translating the path name.
[EMFILE] Too many open file descriptors are currently open for the calling process.
[ENAMETOOLONG]
A component of dirname exceeds
PATH_MAX bytes, or the entire length of dirname
exceeds PATH_MAX − 1 bytes while _POSIX_NO_TRUNC
is in effect.
[ENFILE] Too many open file descriptors are currently open on the system.
[ENOENT] A component of dirname does not exist or dirname points to an empty string.
[ENOMEM]
malloc() failed to provide sufficient memory to process the directory.
[ENOTDIR] A component of dirname is not a directory.
readdir() or readdir_r() might fail if any of the following conditions are encountered:
[EBADF] dirp does not refer to an open directory stream.
[EFAULT] dirp points outside the allocated address space of the process.
[EIO] An I/O error occurred.
[ENOENT] The directory stream to which dirp refers is not located at a valid directory entry.
[ENXIO] Directory may be corrupted.
telldir() might fail if any of the following conditions are encountered:
[EBADF] dirp does not refer to an open directory stream.
[ENOENT] dirp specifies an improper file system block size.
seekdir() might fail if the following condition is encountered:
[ENOENT] dirp specifies an improper file system block size.
closedir() might fail if any of the following conditions are encountered:
[EBADF] dirp does not refer to an open directory stream.
[EFAULT] dirp points outside the allocated address space of the process.
rewinddir() might fail if any of the following conditions are encountered:
[EBADF] dirp does not refer to an open directory stream.
[EFAULT] dirp points outside the allocated address space of the process.
EXAMPLES
The following code searches the current directory for an entry name:
2 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: September 2010