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 
64 struct dirent
65 {
67  char d_name[DIRLEN];
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 
94 typedef struct DIR
95 {
97  int fd;
98 
100  struct dirent *buffer;
101 
104 
107 
109  bool eof;
110 }
111 DIR;
112 
123 extern C DIR * opendir(const char *dirname);
124 
138 extern C struct dirent * readdir(DIR *dirp);
139 
149 extern C int closedir(DIR *dirp);
150 
156 #endif /* __LIBPOSIX_DIRENT_H */
Macros.h
Types.h
types.h
DIRLEN
#define DIRLEN
Maximum length of a directory entry name.
Definition: dirent.h:59
string.h
closedir
C int closedir(DIR *dirp)
Close a directory stream.
Definition: closedir.cpp:22
readdir
C struct dirent * readdir(DIR *dirp)
Read a directory.
Definition: readdir.cpp:21
opendir
C DIR * opendir(const char *dirname)
Open directory associated with file descriptor.
Definition: opendir.cpp:27
DIR::eof
bool eof
End-of-file reached?
Definition: dirent.h:109
C
#define C
Used to define external C functions.
Definition: Macros.h:134
DIR::buffer
struct dirent * buffer
Input buffer.
Definition: dirent.h:100
dirent
Represents a directory entry.
Definition: dirent.h:64
DIR::count
Size count
Number of direct structures in the buffer.
Definition: dirent.h:106
strcmp
int strcmp(const char *dest, const char *src)
Compare two strings.
Definition: strcmp.cpp:20
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
DIR
struct DIR DIR
A type representing a directory stream.
DIR::current
Size current
Index of the current dirent.
Definition: dirent.h:103
DIR
A type representing a directory stream.
Definition: dirent.h:94
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
DIR::fd
int fd
File descriptor returned by opendir().
Definition: dirent.h:97
dirent::d_name
char d_name[DIRLEN]
Name of entry.
Definition: dirent.h:67
dirname
char * dirname(char *path)
Return the directory portion of a pathname.
Definition: dirname.cpp:22
dirent::d_type
u8 d_type
Type of file.
Definition: dirent.h:70