opendir

Opens a directory for reading.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <dirent.h> 
   
  DIR *opendir (
     const char   *pathname);
  

Parameters

pathname

(IN) Points to a path that either is relative to the current working directory or is an absolute pathname. The pathname cannot include any wildcard characters.

Return Values

If successful, returns a pointer to a DIR structure.

Otherwise, returns NULL and sets errno to one of the following:

Decimal

Constant

Description

1

ENOENT

A component of pathname does not name an existing directory, or pathname is an empty string.

6

EACCES

Search permission is denied for the component of the path prefix of pathname or read permission is denied for pathname.

10

ENFILE

Too many files are currently open in the system.

11

EMFILE

The maximum number {OPEN_MAX} of file descriptors are currently open in the calling process.

65

ENAMETOOLONG

The length of the pathname argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.

67

ENOTDIR

A component of pathname is not a directory.

Remarks

The opendir function calls the malloc function to allocate memory for a DIR structure. The closedir function frees the memory.

Information about the first file or directory matching the specified pathname is not placed in the DIR structure until after the first call to the readdir function.

See Also