The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
21
struct
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)
29
typedef
struct
dir_stream
DIR
;
30
31
/**
32
* open a directory for reading.
33
* @return the stream, or NULL (errno set).
34
*/
35
DIR
*
opendir
(
const
char
*path);
36
/** a directory stream on an open directory (closedir closes fd) */
37
DIR
*
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
*/
43
struct
dirent
*
readdir
(
DIR
*dir);
44
45
/**
46
* close a directory stream and its file descriptor.
47
* @return 0, or -1 (errno set).
48
*/
49
int
closedir
(
DIR
*dir);
50
51
/**
52
* the file descriptor under a directory stream.
53
*/
54
int
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
*/
60
int
getdents
(
int
fd,
void
*buf,
unsigned
int
size);
getdents
int getdents(int fd, void *buf, unsigned int size)
read raw getdents records (the syscall under readdir).
DIR
struct dir_stream DIR
Definition
dirent.h:29
fdopendir
DIR * fdopendir(int fd)
a directory stream on an open directory (closedir closes fd)
dirfd
int dirfd(DIR *dir)
the file descriptor under a directory stream.
readdir
struct dirent * readdir(DIR *dir)
read the next entry.
closedir
int closedir(DIR *dir)
close a directory stream and its file descriptor.
opendir
DIR * opendir(const char *path)
open a directory for reading.
dirent
Definition
dirent.h:22
dirent::d_type
unsigned char d_type
Definition
dirent.h:24
dirent::d_ino
unsigned int d_ino
Definition
dirent.h:23
dirent::d_name
char d_name[256]
Definition
dirent.h:25
src
libc
include
dirent.h
Generated by
1.18.0