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