Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

closedir(3) OSS Library Calls Reference Manual
EXAMPLES
The following example shows how to close a directory after searching for the entry name:
len = strlen(name);
dir_pointer = opendir(".");
for (dp = readdir(dir_pointer); dp != NULL;
dp = readdir(dir_pointer))
if (strlen(dp->d_name) == len && !strcmp(dp->d_name, name)) {
closedir(dir_pointer);
return FOUND;
}
closedir(dir_pointer);
return NOT_FOUND;
RETURN VALUES
Upon successful completion, the closedir( ) function returns the value 0 (zero). Otherwise, the
value -1 is returned.
ERRORS
If any of the following conditions occur, the closedir( ) function sets errno to the corresponding
value:
[EBADF] The dir_pointer parameter does not refer to an open directory stream. This error
is returned instead of [EFAULT] if the process has copied and altered the struc-
ture pointed to by the dir_pointer parameter after the system has freed the buffer
that contains the structure.
[EFAULT] The dir_pointer parameter does not point to a valid directory structure open for
reading.
RELATED INFORMATION
Functions: mkdir(2), opendir(3), readdir(3), rewinddir(3), rmdir(2), seekdir(3), telldir(3).
STANDARDS CONFORMANCE
The closedir( ) function does not return the error value [EINTR].
The POSIX standards leave some features to the implementing vendor to define. The following
features are affected in the HP implementation:
After a call to one of the exec set of functions, all open directory streams are closed
automatically.
The ramifications of having both the parent and child processes access the same OSS
directory after a call to the fork( ) or tdm_fork( ) function are undefined.
Upon return from a successful call to the closedir( ) function, the dir_pointer parameter
no longer points to an accessible object of type DIR.
The consequences of calling directory functions with a dir_pointer parameter that does
not refer to a currently opened directory stream are defined. (The error value [EBADF]
or [EFAULT] is returned or a SIGSEGV or SIGILL signal is returned.)
The error values [EBADF] and [EFAULT] can be returned by the closedir( ) function.
The following are HP extensions to the XPG4 Version 2 specification:
The error value [EFAULT] can be returned.
1120 Hewlett-Packard Company 527187-017