add -s to ls comamnd to print the file size
[clinton/Smoothieware.git] / mbed / src / cpp / DirHandle.h
CommitLineData
172d42d9
AG
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
21typedef int mode_t;
22
23#else
24# include <sys/syslimits.h>
25#endif
26
27#include "FileHandle.h"
28
29struct dirent {
30 char d_name[NAME_MAX+1];
3579deea 31 unsigned int d_fsize;
488825fb 32 bool d_isdir;
172d42d9
AG
33};
34
35namespace mbed {
36
37/** Represents a directory stream. Objects of this type are returned
38 * by a FileSystemLike's opendir method. Implementations must define
39 * at least closedir, readdir and rewinddir.
40 *
41 * If a FileSystemLike class defines the opendir method, then the
42 * directories of an object of that type can be accessed by
43 * DIR *d = opendir("/example/directory") (or opendir("/example")
44 * to open the root of the filesystem), and then using readdir(d) etc.
45 *
46 * The root directory is considered to contain all FileLike and
47 * FileSystemLike objects, so the DIR* returned by opendir("/") will
48 * reflect this.
49 */
50class DirHandle {
51
52public:
53 /** Closes the directory.
54 *
55 * @returns
56 * 0 on success,
57 * -1 on error.
58 */
59 virtual int closedir()=0;
60
61 /** Return the directory entry at the current position, and
62 * advances the position to the next entry.
63 *
64 * @returns
65 * A pointer to a dirent structure representing the
66 * directory entry at the current position, or NULL on reaching
67 * end of directory or error.
68 */
69 virtual struct dirent *readdir()=0;
70
71 /** Resets the position to the beginning of the directory.
72 */
73 virtual void rewinddir()=0;
74
75 /** Returns the current position of the DirHandle.
76 *
77 * @returns
78 * the current position,
79 * -1 on error.
80 */
81 virtual off_t telldir() { return -1; }
82
83 /** Sets the position of the DirHandle.
84 *
85 * @param location The location to seek to. Must be a value returned by telldir.
86 */
87 virtual void seekdir(off_t location) { }
88
89 virtual ~DirHandle() {}
90};
91
92} // namespace mbed
93
94typedef mbed::DirHandle DIR;
95
96extern "C" {
97 DIR *opendir(const char*);
98 struct dirent *readdir(DIR *);
99 int closedir(DIR*);
100 void rewinddir(DIR*);
101 long telldir(DIR*);
102 void seekdir(DIR*, long);
103#if !defined(__GNUC__)
104 int mkdir(const char *name, mode_t n);
105#endif
106};
107
108#endif /* MBED_DIRHANDLE_H */