opendir()

open directory 

Function


SYNOPSIS

#include <sys/types.h>

#include <dirent.h>

DIR *opendir(const char *dirname);


DESCRIPTION

The opendir() function opens a directory stream corresponding to the directory named by the dirname argument. The directory stream is positioned at the first entry. The NuTCRACKER Platform does not implement the type DIR using a file descriptor and hence the number of open directory streams is not limited by OPEN_MAX.

The type DIR (defined in <dirent.h>) represents a directory stream, which is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. Files can be removed from or added to a directory asynchronously to the operation performed. The opendir() function should be used in conjunction with readdir(), closedir() and rewinddir() to examine the contents of the directory. If a file is removed from the directory after the most recent call to opendir() or rewinddir(), a subsequent call to readdir() returns an entry for that file. If a file is added to the directory after the most recent call to opendir() or rewinddir(), a subsequent call to readdir() does not return an entry for the added file.

All the open directory streams are inherited to a forked child process. After a call to fork(), both parent and child can independently continue processing the directory stream using readdir() or rewinddir() or both. Directory streams are closed after a successful call to exec() and hence execed image cannot use the directory streams opened in the execing process.


PARAMETERS

dirname 

Is the name of the directory to which a directory stream is to be opened.


RETURN VALUES

If successful, opendir() returns a pointer to an object of type DIR. This pointer is set to the first entry in the directory. If failed, it returns a NULL pointer and sets errno to the corresponding value.

EACCES 

Search permission is denied for a component of the path name prefix of dirname or read permission is denied for the directory.

ENAMETOOLONG 

The length of the dirname parameter exceeds PATH_MAX or a path name component is longer than NAME_MAX.

ENOENT 

The named directory does not exist or dirname points to an empty string or a component of dirname is not a directory.

ENOTDIR 

The argument dirname does not refer to a directory.

ENOMEM 

Not enough memory to create the directory stream.


CONFORMANCE

POSIX.1 (1996).


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
closedir(), mkdir(), readdir(), rewinddir(), rmdir(), seekdir(), telldir()


MKS Toolkit 9.2 Documentation Build 16.