KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
dirent.h
Go to the documentation of this file.
1 /* KallistiOS 2.0.0
2 
3  dirent.h
4  Copyright (C)2003 Dan Potter
5 
6 */
7 
8 /** \file dirent.h
9  \brief Standard POSIX dirent functionality
10 
11  This partially implements the standard POSIX dirent.h functionality.
12 
13  \author Dan Potter
14 */
15 
16 #ifndef __SYS_DIRENT_H
17 #define __SYS_DIRENT_H
18 
19 #include <unistd.h>
20 #include <arch/types.h>
21 #include <kos/fs.h>
22 
23 /** \brief The POSIX dirent which describes a directory entry
24  */
25 struct dirent {
26  int d_ino; /**< \brief the file number */
27  off_t d_off; /**< \brief the file offset */
28  uint16 d_reclen; /**< \brief the record length */
29  uint8 d_type; /**< \brief the type */
30  char d_name[256]; /**< \brief the entry name */
31 };
32 
33 /** \brief the DIR structure in KOS
34 
35  In KOS, DIR * is just an fd, but we use a struct so we can also include the
36  POSIX dirent.
37 */
38 typedef struct {
39  file_t fd; /**< \brief the file descriptor */
40  struct dirent d_ent; /**< \brief the POSIX dirent */
41 } DIR;
42 
43 // Standard UNIX dir functions. Not all of these are fully functional
44 // right now due to lack of support in KOS.
45 
46 // All of these work.
47 /** \brief Opens a directory based on the specified name
48 
49  The directory specified by name is opened if it exists and returns a
50  directory structure that must be later closed with closedir.
51 
52  \param name The string name of the dir to open.
53  \return A directory structure that can be used with readdir
54  \note I believe you can use relative paths with opendir, but it depends on
55  the current working directory (getcwd)
56  \see closedir
57  \see readdir
58 */
59 DIR *opendir(const char *name);
60 
61 /** \brief Closes a currently opened directory
62 
63  Close a DIR that was previously opened with opendir.
64 
65  \param dir The DIR that was returned from an opendir.
66  \return 0 on success, or -1 on error.
67 */
68 int closedir(DIR *dir);
69 
70 /** \brief Read the contents of an open directory
71 
72  Read the contents of an open directory and returns a pointer to the current
73  directory entry. Recurring calls to readdir return the next directory entry.
74 
75  \note Do not free the returned dirent
76  \param dir The directory structure that was returned from an opendir
77  \return A pointer to the current diretory entry or NULL when there are no
78  more entries.
79 */
80 struct dirent *readdir(DIR *dir);
81 
82 /** \brief Not implemented */
83 void rewinddir(DIR *dir);
84 /** \brief Not implemented */
85 int scandir(const char *dir, struct dirent ***namelist,
86  int(*filter)(const struct dirent *),
87  int(*compar)(const struct dirent **, const struct dirent **));
88 /** \brief Not implemented */
89 void seekdir(DIR *dir, off_t offset);
90 /** \brief Not implemented */
91 off_t telldir(DIR *dir);
92 
93 #endif
94