open directory 



#include <sys/types.h>

#include <dirent.h>

DIR *opendir(const char *dirname);


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.



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


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.


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


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


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


The argument dirname does not refer to a directory.


Not enough memory to create the directory stream.


POSIX.1 (1996).




Directory names are treated as multibyte sequences and are converted to Unicode (UTF-16) before passing to Win32. The conversion is either performed based on the current thread locale, set using uselocale() or the process locale as set by a call to setlocale(), and overridden by _NutConf() _NC_SET_ANSI_LOCALE and _NC_SET_UTF8_LOCALE options. Under all other conditions, the multibyte sequences are considered to be from the ANSI code page for the current windows system locale.


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


closedir(), mkdir(), readdir(), rewinddir(), rmdir(), seekdir(), telldir(), xlocale()

PTC MKS Toolkit 10.3 Documentation Build 39.