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