The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
dirent.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file dirent.h
5 * @brief reading directories: opendir, readdir, closedir.
6 *
7 * built on the getdents syscall, whose record layout and DT_ values are ABI
8 * (src/kernel/vfs/dirent.h).
9 */
10
11// d_type values
12#define DT_UNKNOWN 0
13#define DT_FIFO 1
14#define DT_CHR 2
15#define DT_DIR 4
16#define DT_BLK 6
17#define DT_REG 8
18#define DT_LNK 10
19#define DT_SOCK 12
20
21struct dirent
22{
23 unsigned int d_ino;
24 unsigned char d_type;
25 char d_name[256];
26};
27
28// an open directory stream (its fields are private to the libc)
29typedef struct dir_stream DIR;
30
31/**
32 * open a directory for reading.
33 * @return the stream, or NULL (errno set).
34 */
35DIR *opendir(const char *path);
36/** a directory stream on an open directory (closedir closes fd) */
37DIR *fdopendir(int fd);
38
39/**
40 * read the next entry. the returned struct is overwritten by the next call.
41 * @return the entry, or NULL at the end of the directory or on error.
42 */
43struct dirent *readdir(DIR *dir);
44
45/**
46 * close a directory stream and its file descriptor.
47 * @return 0, or -1 (errno set).
48 */
49int closedir(DIR *dir);
50
51/**
52 * the file descriptor under a directory stream.
53 */
54int dirfd(DIR *dir);
55
56/**
57 * read raw getdents records (the syscall under readdir).
58 * @return bytes read, 0 at the end, or -1 (errno set).
59 */
60int getdents(int fd, void *buf, unsigned int size);
int getdents(int fd, void *buf, unsigned int size)
read raw getdents records (the syscall under readdir).
struct dir_stream DIR
Definition dirent.h:29
DIR * fdopendir(int fd)
a directory stream on an open directory (closedir closes fd)
int dirfd(DIR *dir)
the file descriptor under a directory stream.
struct dirent * readdir(DIR *dir)
read the next entry.
int closedir(DIR *dir)
close a directory stream and its file descriptor.
DIR * opendir(const char *path)
open a directory for reading.
Definition dirent.h:22
unsigned char d_type
Definition dirent.h:24
unsigned int d_ino
Definition dirent.h:23
char d_name[256]
Definition dirent.h:25