directory(3c) manual page

NAME

directory, opendir, readdir, readdir_r, telldir, seekdir, rewinddir, closedir - directory operations


SYNOPSIS

#include <dirent.h>

DIR *opendir(const char *filename);

struct dirent *readdir(DIR *dirp);

struct dirent *readdir_r(DIR *dirp,struct dirent *res);

long telldir(DIR *dirp);

void seekdir(DIR *dirp, long loc);

void rewinddir(DIR *dirp);

int closedir(DIR *dirp);


MT-LEVEL

See the NOTES section.


DESCRIPTION


RETURN VALUES


ERRORS


EXAMPLES

Here is a sample program that prints the names of all the files in the current directory:

#include <stdio.h>
#include <dirent.h>

main() {
  DIR *dirp;
  struct dirent *direntp;
 
  dirp = opendir( "." );
  while ( (direntp = readdir( dirp )) != NULL )
    (void)printf( "%s\n", direntp->d_name );
  (void)closedir( dirp );
  return (0);
}


SEE ALSO

getdents(2), dirent(4)


NOTES

The readdir_r() interface is as proposed in the POSIX.4a Draft #6 document, and is subject to change to be compliant to the standard when it is accepted.

When compiling multi-thread applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in multi-thread applications.

readdir() is unsafe in multi-thread applications. readdir_r() is safe, and should be used instead. closedir(), directory(), opendir(), rewinddir(), seekdir(), and telldir() are safe in multi-thread applications.