Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
inc/DirHandle.h@1:ff38e3bad33a, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 17:59:08 2018 +0000
- Revision:
- 1:ff38e3bad33a
- Parent:
- 0:afeca64a6543
Diplomarbeit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martwerl | 0:afeca64a6543 | 1 | /* mbed Microcontroller Library |
| martwerl | 0:afeca64a6543 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| martwerl | 0:afeca64a6543 | 3 | * |
| martwerl | 0:afeca64a6543 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| martwerl | 0:afeca64a6543 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| martwerl | 0:afeca64a6543 | 6 | * in the Software without restriction, including without limitation the rights |
| martwerl | 0:afeca64a6543 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| martwerl | 0:afeca64a6543 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| martwerl | 0:afeca64a6543 | 9 | * furnished to do so, subject to the following conditions: |
| martwerl | 0:afeca64a6543 | 10 | * |
| martwerl | 0:afeca64a6543 | 11 | * The above copyright notice and this permission notice shall be included in |
| martwerl | 0:afeca64a6543 | 12 | * all copies or substantial portions of the Software. |
| martwerl | 0:afeca64a6543 | 13 | * |
| martwerl | 0:afeca64a6543 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| martwerl | 0:afeca64a6543 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| martwerl | 0:afeca64a6543 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| martwerl | 0:afeca64a6543 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| martwerl | 0:afeca64a6543 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| martwerl | 0:afeca64a6543 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| martwerl | 0:afeca64a6543 | 20 | * SOFTWARE. |
| martwerl | 0:afeca64a6543 | 21 | */ |
| martwerl | 0:afeca64a6543 | 22 | #ifndef MBED_DIRHANDLE_H |
| martwerl | 0:afeca64a6543 | 23 | #define MBED_DIRHANDLE_H |
| martwerl | 0:afeca64a6543 | 24 | |
| martwerl | 0:afeca64a6543 | 25 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
| martwerl | 0:afeca64a6543 | 26 | # define NAME_MAX 255 |
| martwerl | 0:afeca64a6543 | 27 | typedef int mode_t; |
| martwerl | 0:afeca64a6543 | 28 | |
| martwerl | 0:afeca64a6543 | 29 | #else |
| martwerl | 0:afeca64a6543 | 30 | # include <sys/syslimits.h> |
| martwerl | 0:afeca64a6543 | 31 | #endif |
| martwerl | 0:afeca64a6543 | 32 | |
| martwerl | 0:afeca64a6543 | 33 | #include "FileHandle.h" |
| martwerl | 0:afeca64a6543 | 34 | |
| martwerl | 0:afeca64a6543 | 35 | struct dirent { |
| martwerl | 0:afeca64a6543 | 36 | char d_name[NAME_MAX+1]; |
| martwerl | 0:afeca64a6543 | 37 | }; |
| martwerl | 0:afeca64a6543 | 38 | |
| martwerl | 0:afeca64a6543 | 39 | namespace mbed { |
| martwerl | 0:afeca64a6543 | 40 | |
| martwerl | 0:afeca64a6543 | 41 | /** Represents a directory stream. Objects of this type are returned |
| martwerl | 0:afeca64a6543 | 42 | * by a FileSystemLike's opendir method. Implementations must define |
| martwerl | 0:afeca64a6543 | 43 | * at least closedir, readdir and rewinddir. |
| martwerl | 0:afeca64a6543 | 44 | * |
| martwerl | 0:afeca64a6543 | 45 | * If a FileSystemLike class defines the opendir method, then the |
| martwerl | 0:afeca64a6543 | 46 | * directories of an object of that type can be accessed by |
| martwerl | 0:afeca64a6543 | 47 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
| martwerl | 0:afeca64a6543 | 48 | * to open the root of the filesystem), and then using readdir(d) etc. |
| martwerl | 0:afeca64a6543 | 49 | * |
| martwerl | 0:afeca64a6543 | 50 | * The root directory is considered to contain all FileLike and |
| martwerl | 0:afeca64a6543 | 51 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
| martwerl | 0:afeca64a6543 | 52 | * reflect this. |
| martwerl | 0:afeca64a6543 | 53 | */ |
| martwerl | 0:afeca64a6543 | 54 | class DirHandle { |
| martwerl | 0:afeca64a6543 | 55 | |
| martwerl | 0:afeca64a6543 | 56 | public: |
| martwerl | 0:afeca64a6543 | 57 | /** Closes the directory. |
| martwerl | 0:afeca64a6543 | 58 | * |
| martwerl | 0:afeca64a6543 | 59 | * @returns |
| martwerl | 0:afeca64a6543 | 60 | * 0 on success, |
| martwerl | 0:afeca64a6543 | 61 | * -1 on error. |
| martwerl | 0:afeca64a6543 | 62 | */ |
| martwerl | 0:afeca64a6543 | 63 | virtual int closedir()=0; |
| martwerl | 0:afeca64a6543 | 64 | |
| martwerl | 0:afeca64a6543 | 65 | /** Return the directory entry at the current position, and |
| martwerl | 0:afeca64a6543 | 66 | * advances the position to the next entry. |
| martwerl | 0:afeca64a6543 | 67 | * |
| martwerl | 0:afeca64a6543 | 68 | * @returns |
| martwerl | 0:afeca64a6543 | 69 | * A pointer to a dirent structure representing the |
| martwerl | 0:afeca64a6543 | 70 | * directory entry at the current position, or NULL on reaching |
| martwerl | 0:afeca64a6543 | 71 | * end of directory or error. |
| martwerl | 0:afeca64a6543 | 72 | */ |
| martwerl | 0:afeca64a6543 | 73 | virtual struct dirent *readdir()=0; |
| martwerl | 0:afeca64a6543 | 74 | |
| martwerl | 0:afeca64a6543 | 75 | /** Resets the position to the beginning of the directory. |
| martwerl | 0:afeca64a6543 | 76 | */ |
| martwerl | 0:afeca64a6543 | 77 | virtual void rewinddir()=0; |
| martwerl | 0:afeca64a6543 | 78 | |
| martwerl | 0:afeca64a6543 | 79 | /** Returns the current position of the DirHandle. |
| martwerl | 0:afeca64a6543 | 80 | * |
| martwerl | 0:afeca64a6543 | 81 | * @returns |
| martwerl | 0:afeca64a6543 | 82 | * the current position, |
| martwerl | 0:afeca64a6543 | 83 | * -1 on error. |
| martwerl | 0:afeca64a6543 | 84 | */ |
| martwerl | 0:afeca64a6543 | 85 | virtual off_t telldir() { return -1; } |
| martwerl | 0:afeca64a6543 | 86 | |
| martwerl | 0:afeca64a6543 | 87 | /** Sets the position of the DirHandle. |
| martwerl | 0:afeca64a6543 | 88 | * |
| martwerl | 0:afeca64a6543 | 89 | * @param location The location to seek to. Must be a value returned by telldir. |
| martwerl | 0:afeca64a6543 | 90 | */ |
| martwerl | 0:afeca64a6543 | 91 | virtual void seekdir(off_t location) { } |
| martwerl | 0:afeca64a6543 | 92 | |
| martwerl | 0:afeca64a6543 | 93 | virtual ~DirHandle() {} |
| martwerl | 0:afeca64a6543 | 94 | }; |
| martwerl | 0:afeca64a6543 | 95 | |
| martwerl | 0:afeca64a6543 | 96 | } // namespace mbed |
| martwerl | 0:afeca64a6543 | 97 | |
| martwerl | 0:afeca64a6543 | 98 | typedef mbed::DirHandle DIR; |
| martwerl | 0:afeca64a6543 | 99 | |
| martwerl | 0:afeca64a6543 | 100 | extern "C" { |
| martwerl | 0:afeca64a6543 | 101 | DIR *opendir(const char*); |
| martwerl | 0:afeca64a6543 | 102 | struct dirent *readdir(DIR *); |
| martwerl | 0:afeca64a6543 | 103 | int closedir(DIR*); |
| martwerl | 0:afeca64a6543 | 104 | void rewinddir(DIR*); |
| martwerl | 0:afeca64a6543 | 105 | long telldir(DIR*); |
| martwerl | 0:afeca64a6543 | 106 | void seekdir(DIR*, long); |
| martwerl | 0:afeca64a6543 | 107 | int mkdir(const char *name, mode_t n); |
| martwerl | 0:afeca64a6543 | 108 | }; |
| martwerl | 0:afeca64a6543 | 109 | |
| martwerl | 0:afeca64a6543 | 110 | #endif /* MBED_DIRHANDLE_H */ |
| martwerl | 0:afeca64a6543 | 111 |