Closes directories.
#include <dirent.h> int closedir (DIR *dir_pointer);
The type DIR, which is defined in the <dirent.h> header file, represents a directory stream that is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove files from or add files to a directory asynchronously to the operation of the readdir function.
The following example shows how to search a directory for the entry name, using the opendir, readdir, and closedir functions:
len = strlen(name); dir_pointer = opendir("."); for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { closedir(dir_pointer); return FOUND; } closedir(dir_pointer); return NOT_FOUND;
0 | Indicates success. |
-1 | Indicates an error and is further specified in the global errno. |