HP-UX Reference (11i v2 03/08) - 3 Library Functions A-M (vol 6)
d
directory(3C) directory(3C)
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 reli-
able 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 dir-
name 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.
[ENOMEM]
malloc() failed to provide sufficient memory to process the directory.
[ENOTDIR] A component of dirname is not a directory.
[ENOENT] The dirname argument points to an empty string.
readdir() or readdir_r() might fail if any of the following conditions are encountered:
[EBADF] dirp does not refer to an open directory stream.
[ENOENT] The directory stream to which dirp refers is not located at a valid directory
entry.
[EFAULT] dirp points outside the allocated address space of the process.
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:
DIR *dirp;
struct dirent *dp;
dirp = opendir(".");
while ((dp = readdir(dirp)) != NULL) {
if (strcmp(dp->d_name, name) == 0) {
(void) closedir(dirp);
HP-UX 11i Version 2: August 2003 − 2 − Hewlett-Packard Company Section 3−−187