FreeNOS
dirent.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBPOSIX_DIRENT_H
19#define __LIBPOSIX_DIRENT_H
20
21#include <Macros.h>
22#include <Types.h>
23#include "sys/types.h"
24#include "string.h"
25
35#define DT_UNKNOWN 0
36
38#define DT_FIFO 1
39
41#define DT_CHR 2
42
44#define DT_DIR 4
45
47#define DT_BLK 6
48
50#define DT_REG 8
51
53#define DT_LNK 10
54
56#define DT_SOCK 12
57
59#define DIRLEN 64
60
64struct dirent
65{
68
71
72#ifdef CPP
73
81 bool operator == (struct dirent *d)
82 {
83 return strcmp(d->d_name, d_name) == 0 && d->d_type == d_type;
84 }
85
86#endif /* CPP */
87};
88
94typedef struct DIR
95{
97 int fd;
98
100 struct dirent *buffer;
101
104
107
109 bool eof;
110}
112
123extern C DIR * opendir(const char *dirname);
124
138extern C struct dirent * readdir(DIR *dirp);
139
149extern C int closedir(DIR *dirp);
150
156#endif /* __LIBPOSIX_DIRENT_H */
C struct dirent * readdir(DIR *dirp)
Read a directory.
Definition readdir.cpp:21
C char * dirname(char *path)
Return the directory portion of a pathname.
Definition dirname.cpp:22
C int strcmp(const char *dest, const char *src)
Compare two strings.
Definition strcmp.cpp:20
#define DIRLEN
Maximum length of a directory entry name.
Definition dirent.h:59
C DIR * opendir(const char *dirname)
Open directory associated with file descriptor.
Definition opendir.cpp:27
C int closedir(DIR *dirp)
Close a directory stream.
Definition closedir.cpp:22
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define C
Used to define external C functions.
Definition Macros.h:134
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
A type representing a directory stream.
Definition dirent.h:95
Size count
Number of direct structures in the buffer.
Definition dirent.h:106
bool eof
End-of-file reached?
Definition dirent.h:109
struct dirent * buffer
Input buffer.
Definition dirent.h:100
Size current
Index of the current dirent.
Definition dirent.h:103
int fd
File descriptor returned by opendir().
Definition dirent.h:97
Represents a directory entry.
Definition dirent.h:65
u8 d_type
Type of file.
Definition dirent.h:70
char d_name[DIRLEN]
Name of entry.
Definition dirent.h:67