CLOSEDIR(3C) Standard C Library Functions CLOSEDIR(3C)

closedir
close a directory stream

#include <sys/types.h>
#include <dirent.h>

int
closedir(DIR *dirp);

The closedir() function closes the directory stream referred to by the argument dirp, which generally came from calling opendir(3C) or fdopendir(3C). Upon return, the value of dirp will no longer point to an accessible object of the type DIR. The underlying file descriptor for the directory stream will be closed. This includes a DIR created by passing a file descriptor to fdopendir(3C).

When the directory stream is closed, any memory that is associated with the stream will no longer be valid. Most notably, the dirent structures returned from readdir(3C) use memory associated with the corresponding DIR * argument. Each directory stream has its own independent memory. Closing one stream does not impact the validity of other streams.

Upon successful completion, the closedir() function returns 0. Otherwise, -1 is returned and errno is set to indicate the error.

The closedir() function may fail if:
The dirp argument does not refer to an open directory stream.
The closedir() function was interrupted by a signal.

Standard

Safe

fdopendir(3C), opendir(3C), readdir(3C), attributes(7)
February 25, 2021 OmniOS