Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 8

closedir()

Close a directory

Synopsis:

#include <dirent.h>

int closedir( DIR * dirp );

Arguments:

dirp
A directory pointer for the directory you want to close.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The closedir() function closes the directory specified by dirp, and frees the memory allocated by opendir().


Note: The result of using a directory stream after calling one of the exec*() or spawn*() family of functions is undefined. After a call to the fork() function, either the parent or the child (but not both) may continue processing the directory stream using the readdir() and rewinddir() functions. If both the parent and child processes use these functions, the result is undefined. Either or both processes may call the closedir() function.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EBADF
The dirp argument doesn't refer to an open directory stream.
EINTR
The closedir() call was interrupted by a signal.

Examples:

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;
}

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

dirent, errno, opendir(), readdir(), readdir_r(), rewinddir(), seekdir(), telldir()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 196

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/closedir.html on line 196