delorie.com/djgpp/doc/libc/libc_646.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

readdir

Syntax

 
#include <dirent.h>

struct dirent *readdir(DIR *dir);

Description

This function reads entries from a directory opened by opendir (see section opendir). It returns the information in a static buffer with this format:

 
struct dirent {
  unsigned short d_namlen;  /* The length of the name (like strlen) */
  char d_name[MAXNAMLEN+1]; /* The name */
  mode_t d_type;            /* The file's type */
};

Note that some directory entries might be skipped by readdir, depending on the bits set in the global variable __opendir_flags. See section opendir.

The possible values of the d_type member are:

DT_REG
This is a regular file.
DT_BLK
The file is a block device.
DT_CHR
The file is a character device.
DT_DIR
The file is a directory.
DT_FIFO
This is a pipe (never happens in DJGPP).
DT_LABEL
The file is a volume label.
DT_LNK
The file is a symlink.
DT_SOCK
The file is a socket.
DT_UNKNOWN
The file's type is unknown. This value is put into the d_type member if the exact file's type is too expensive to compute. If the __OPENDIR_NO_D_TYPE flag is set in the global variable __opendir_flags, all files get marked with DT_UNKNOWN.

The macro DTTOIF (see section DTTOIF) can be used to convert the d_type member to the equivalent value of the st_mode member of struct stat, see stat.

Return Value

A pointer to a static buffer that is overwritten with each call.

Portability

ANSI/ISO C No
POSIX 1003.2-1992; 1003.1-2001 (see note 1)

Notes:

  1. The __opendir_flags variable is DJGPP-specific. The d_type member is an extension available on some systems such as GNU/Linux.

Example

 
DIR *d = opendir(".");
struct dirent *de;
while (de = readdir(d))
  puts(de->d_name);
closedir(d);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004