Upgrade gcc4mbed project used by Smoothie.
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / DirHandle.h
1 /* mbed Microcontroller Library - DirHandler
2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
3 */
4
5 #ifndef MBED_DIRHANDLE_H
6 #define MBED_DIRHANDLE_H
7
8 #ifdef __ARMCC_VERSION
9 # define NAME_MAX 255
10 typedef int mode_t;
11 #else
12 # include <sys/syslimits.h>
13 #endif
14 #include "FileHandle.h"
15
16 struct dirent {
17 char d_name[NAME_MAX+1];
18 };
19
20 namespace mbed {
21
22 /* Class DirHandle
23 * Represents a directory stream. Objects of this type are returned
24 * by a FileSystemLike's opendir method. Implementations must define
25 * at least closedir, readdir and rewinddir.
26 *
27 * If a FileSystemLike class defines the opendir method, then the
28 * directories of an object of that type can be accessed by
29 * DIR *d = opendir("/example/directory") (or opendir("/example")
30 * to open the root of the filesystem), and then using readdir(d) etc.
31 *
32 * The root directory is considered to contain all FileLike and
33 * FileSystemLike objects, so the DIR* returned by opendir("/") will
34 * reflect this.
35 */
36 class DirHandle {
37
38 public:
39 /* Function closedir
40 * Closes the directory.
41 *
42 * Variables
43 * returns - 0 on success, or -1 on error.
44 */
45 virtual int closedir()=0;
46
47 /* Function readdir
48 * Return the directory entry at the current position, and
49 * advances the position to the next entry.
50 *
51 * Returns
52 * A pointer to a dirent structure representing the
53 * directory entry at the current position, or NULL on reaching
54 * end of directory or error.
55 */
56 virtual struct dirent *readdir()=0;
57
58 /* Function rewinddir
59 * Resets the position to the beginning of the directory.
60 */
61 virtual void rewinddir()=0;
62
63 /* Function telldir
64 * Returns the current position of the DirHandle.
65 *
66 * Returns
67 * The current position, or -1 on error.
68 */
69 virtual off_t telldir() { return -1; }
70
71 /* Function seekdir
72 * Sets the position of the DirHandle.
73 *
74 * Variables
75 * location - The location to seek to. Must be a value returned
76 * by telldir.
77 */
78 virtual void seekdir(off_t location) { }
79
80 };
81
82 } // namespace mbed
83
84 typedef mbed::DirHandle DIR;
85
86 extern "C" {
87 DIR *opendir(const char*);
88 struct dirent *readdir(DIR *);
89 int closedir(DIR*);
90 void rewinddir(DIR*);
91 long telldir(DIR*);
92 void seekdir(DIR*, long);
93 int mkdir(const char *name, mode_t n);
94 };
95
96 #endif /* MBED_DIRHANDLE_H */