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