Directory System Call Support

Functions

DIR *opendir(const char *name)

Open a directory.

Parameters:

name – [in] Directory path to open

Returns:

a pointer to the directory stream. On error, NULL is returned, and errno is set appropriately.

struct dirent *readdir(DIR *dirp)

Read a directory.

Parameters:

dirp – [in] directory stream provided by opendir

Returns:

On success, a pointer to a dirent structure. (This structure may be statically allocated; do not attempt to free it.)

long telldir(DIR *dirp)

return current location in directory stream. This function may not supported by all filesystem drivers

Parameters:

dirp – [in] directory stream provided by opendir

Returns:

On success, function returns the current location in the directory stream. On error, -1 is returned, and errno is set appropriately

void rewinddir(DIR *dirp)

reset directory stream. This function may not supported by all filesystem drivers

Parameters:

dirp – [in] directory stream provided by opendir

void seekdir(DIR *dirp, long loc)

set the position of the next readdir call in the directory stream. This function may not supported by all filesystem drivers

Parameters:
  • dirp – [in] directory stream provided by opendir

  • loc – [in] a value returned by a previous call to telldir

int closedir(DIR *dirp)

Close a directory.

Parameters:

dirp – [in] directory stream provided by opendir

Returns:

0 on success. On error, -1 is returned, and errno is set appropriately.

Structures

struct dirent

Directory entry structure

Public Members

ino_t d_ino

inode number (Unused)

off_t d_off

offset to the next dirent (unused)

unsigned long d_reclen

length of this record

unsigned char d_type

type of file _dtype_e

char d_name[256]

filename

Type Definitions

typedef void DIR

Directory stream pointer type

Enumerations

enum _dtype_e

File type flags for d_type

Values:

enumerator DT_UNKNOWN

The file type could not be determined

enumerator DT_FIFO

FIFO File type

enumerator DT_CHR

Special file type: Character device

enumerator DT_DIR

Directory

enumerator DT_BLK

Special file type: Block device

enumerator DT_REG

Regular File type

enumerator DT_LNK

File is a symbolic link

enumerator DT_SOCK

File is a UNIX domain socket