Close a directory
#include <dirent.h> int closedir( DIR * dirp );
BlackBerry 10.0.0
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The closedir() function closes the directory specified by dirp, and frees the memory allocated by opendir() .
Get a list of files contained in the directory /home/kenny:
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
int main( void )
{
DIR *dirp;
struct dirent *direntp;
dirp = opendir( "/home/kenny" );
if( dirp != NULL ) {
for(;;) {
direntp = readdir( dirp );
if( direntp == NULL ) {
break;
}
printf( "%s\n", direntp->d_name );
}
closedir( dirp );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |