]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/DirHandle.h
Merge commit '20b787fc1284176834cbe7ca2134e4b36bec5828'
[max/tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / api / DirHandle.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MBED_DIRHANDLE_H
17 #define MBED_DIRHANDLE_H
18
19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
20 #   define NAME_MAX 255
21 typedef int mode_t;
22
23 #else
24 #   include <sys/syslimits.h>
25 #endif
26
27 #include "FileHandle.h"
28
29 struct dirent {
30     char d_name[NAME_MAX+1];
31 };
32
33 namespace mbed {
34
35 /** Represents a directory stream. Objects of this type are returned
36  *  by a FileSystemLike's opendir method. Implementations must define
37  *  at least closedir, readdir and rewinddir.
38  *
39  *  If a FileSystemLike class defines the opendir method, then the
40  *  directories of an object of that type can be accessed by
41  *  DIR *d = opendir("/example/directory") (or opendir("/example")
42  *  to open the root of the filesystem), and then using readdir(d) etc.
43  *
44  *  The root directory is considered to contain all FileLike and
45  *  FileSystemLike objects, so the DIR* returned by opendir("/") will
46  *  reflect this.
47  */
48 class DirHandle {
49
50 public:
51     /** Closes the directory.
52      *
53      *  @returns
54      *    0 on success,
55      *   -1 on error.
56      */
57     virtual int closedir()=0;
58
59     /** Return the directory entry at the current position, and
60      *  advances the position to the next entry.
61      *
62      * @returns
63      *  A pointer to a dirent structure representing the
64      *  directory entry at the current position, or NULL on reaching
65      *  end of directory or error.
66      */
67     virtual struct dirent *readdir()=0;
68
69     /** Resets the position to the beginning of the directory.
70      */
71     virtual void rewinddir()=0;
72
73     /** Returns the current position of the DirHandle.
74      *
75      * @returns
76      *   the current position,
77      *  -1 on error.
78      */
79     virtual off_t telldir() { return -1; }
80
81     /** Sets the position of the DirHandle.
82      *
83      *  @param location The location to seek to. Must be a value returned by telldir.
84      */
85     virtual void seekdir(off_t location) { }
86
87     virtual ~DirHandle() {}
88 };
89
90 } // namespace mbed
91
92 typedef mbed::DirHandle DIR;
93
94 extern "C" {
95     DIR *opendir(const char*);
96     struct dirent *readdir(DIR *);
97     int closedir(DIR*);
98     void rewinddir(DIR*);
99     long telldir(DIR*);
100     void seekdir(DIR*, long);
101     int mkdir(const char *name, mode_t n);
102 };
103
104 #endif /* MBED_DIRHANDLE_H */