- Function
Read a directory.
- Header
- Declaration
struct dirent* __fastcall__ readdir (DIR* dir);
- Description
readdir
reads the next directory entry from the directory stream pointed to bydir
. It stores the data in adirent
structure and returns a pointer to it. If the end of directory is reached, or an error occurs, NULL is returned. In case of errors, an error code is stored intoerrno
.- Limits
- The function is only available as fastcall function, so it may only be used in presence of a prototype.
- The returned pointer may point to a statically allocated instance of
struct dirent
, so it may get overwritten by subsequent calls toreaddir
.- On several platforms, namely the CBMs and the Atari, the disk drives get confused when opening/closing files between directory reads. So for example a program that reads the list of files on a disk, and after each call to
readdir
, opens the file to process it, will fail.
Possible solutions are reading the directory into memory before processing the file list, or to reset the directory by seeking to the correct position after opening/closing a file:seekdir (DIR, telldir (DIR));Platforms known to work without problems are: Apple.- Availability
POSIX 1003.1
- See also
- Example
None.