The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
dirent.h File Reference

reading directories: opendir, readdir, closedir. More...

Go to the source code of this file.

Data Structures

struct  dirent

Macros

#define DT_UNKNOWN   0
#define DT_FIFO   1
#define DT_CHR   2
#define DT_DIR   4
#define DT_BLK   6
#define DT_REG   8
#define DT_LNK   10
#define DT_SOCK   12

Typedefs

typedef struct dir_stream DIR

Functions

DIR * opendir (const char *path)
 open a directory for reading.
DIR * fdopendir (int fd)
 a directory stream on an open directory (closedir closes fd)
struct dirent * readdir (DIR *dir)
 read the next entry.
int closedir (DIR *dir)
 close a directory stream and its file descriptor.
int dirfd (DIR *dir)
 the file descriptor under a directory stream.
int getdents (int fd, void *buf, unsigned int size)
 read raw getdents records (the syscall under readdir).

Detailed Description

reading directories: opendir, readdir, closedir.

built on the getdents syscall, whose record layout and DT_ values are ABI (src/kernel/vfs/dirent.h).

Macro Definition Documentation

◆ DT_UNKNOWN

#define DT_UNKNOWN   0

◆ DT_FIFO

#define DT_FIFO   1

◆ DT_CHR

#define DT_CHR   2

◆ DT_DIR

#define DT_DIR   4

◆ DT_BLK

#define DT_BLK   6

◆ DT_REG

#define DT_REG   8

◆ DT_LNK

#define DT_LNK   10

◆ DT_SOCK

#define DT_SOCK   12

Typedef Documentation

◆ DIR

typedef struct dir_stream DIR

Function Documentation

◆ opendir()

DIR * opendir ( const char * path)

open a directory for reading.

Returns
the stream, or NULL (errno set).

◆ fdopendir()

DIR * fdopendir ( int fd)

a directory stream on an open directory (closedir closes fd)

◆ readdir()

struct dirent * readdir ( DIR * dir)

read the next entry.

the returned struct is overwritten by the next call.

Returns
the entry, or NULL at the end of the directory or on error.

◆ closedir()

int closedir ( DIR * dir)

close a directory stream and its file descriptor.

Returns
0, or -1 (errno set).

◆ dirfd()

int dirfd ( DIR * dir)

the file descriptor under a directory stream.

◆ getdents()

int getdents ( int fd,
void * buf,
unsigned int size )

read raw getdents records (the syscall under readdir).

Returns
bytes read, 0 at the end, or -1 (errno set).