An open directory needs to be closed when the program is finished with it. The synopsis for closedir(3) is as follows:
#include <sys/types.h> #include <dirent.h> int closedir(DIR *dirp);
This function is simply called with a pointer to an open DIR structure. The value returned is -1 if the close operation fails, and the error is posted to errno. Otherwise, closedir(3) returns 0 upon success. An example is as follows:
DIR *dirp; /* Ptr to open directory */ dirp = opendir("/etc"); if ( !dirp ) { /* report error */ } else { /* Close the directory now */ if ( closedir(dirp) == -1 ) { /* Report closedir(3) error */ } }
The example simply opens the directory /etc and then closes it again.
3.149.251.154