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