nothing changed
Fork of mbed by
DirHandle.h@1:27d81db81dd7, 2015-03-03 (annotated)
- Committer:
- Jing_Qiu
- Date:
- Tue Mar 03 00:55:57 2015 +0000
- Revision:
- 1:27d81db81dd7
- Parent:
- 0:a8fa94490a0a
revise
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gokmenascioglu | 0:a8fa94490a0a | 1 | /* mbed Microcontroller Library - DirHandler |
gokmenascioglu | 0:a8fa94490a0a | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
gokmenascioglu | 0:a8fa94490a0a | 3 | */ |
gokmenascioglu | 0:a8fa94490a0a | 4 | |
gokmenascioglu | 0:a8fa94490a0a | 5 | #ifndef MBED_DIRHANDLE_H |
gokmenascioglu | 0:a8fa94490a0a | 6 | #define MBED_DIRHANDLE_H |
gokmenascioglu | 0:a8fa94490a0a | 7 | |
gokmenascioglu | 0:a8fa94490a0a | 8 | #ifdef __ARMCC_VERSION |
gokmenascioglu | 0:a8fa94490a0a | 9 | # define NAME_MAX 255 |
gokmenascioglu | 0:a8fa94490a0a | 10 | typedef int mode_t; |
gokmenascioglu | 0:a8fa94490a0a | 11 | #else |
gokmenascioglu | 0:a8fa94490a0a | 12 | # include <sys/syslimits.h> |
gokmenascioglu | 0:a8fa94490a0a | 13 | #endif |
gokmenascioglu | 0:a8fa94490a0a | 14 | #include "FileHandle.h" |
gokmenascioglu | 0:a8fa94490a0a | 15 | |
gokmenascioglu | 0:a8fa94490a0a | 16 | struct dirent { |
gokmenascioglu | 0:a8fa94490a0a | 17 | char d_name[NAME_MAX+1]; |
gokmenascioglu | 0:a8fa94490a0a | 18 | }; |
gokmenascioglu | 0:a8fa94490a0a | 19 | |
gokmenascioglu | 0:a8fa94490a0a | 20 | namespace mbed { |
gokmenascioglu | 0:a8fa94490a0a | 21 | |
gokmenascioglu | 0:a8fa94490a0a | 22 | /* Class DirHandle |
gokmenascioglu | 0:a8fa94490a0a | 23 | * Represents a directory stream. Objects of this type are returned |
gokmenascioglu | 0:a8fa94490a0a | 24 | * by a FileSystemLike's opendir method. Implementations must define |
gokmenascioglu | 0:a8fa94490a0a | 25 | * at least closedir, readdir and rewinddir. |
gokmenascioglu | 0:a8fa94490a0a | 26 | * |
gokmenascioglu | 0:a8fa94490a0a | 27 | * If a FileSystemLike class defines the opendir method, then the |
gokmenascioglu | 0:a8fa94490a0a | 28 | * directories of an object of that type can be accessed by |
gokmenascioglu | 0:a8fa94490a0a | 29 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
gokmenascioglu | 0:a8fa94490a0a | 30 | * to open the root of the filesystem), and then using readdir(d) etc. |
gokmenascioglu | 0:a8fa94490a0a | 31 | * |
gokmenascioglu | 0:a8fa94490a0a | 32 | * The root directory is considered to contain all FileLike and |
gokmenascioglu | 0:a8fa94490a0a | 33 | * FileSystemLike objects, so the DIR* returned by opendir("/") will |
gokmenascioglu | 0:a8fa94490a0a | 34 | * reflect this. |
gokmenascioglu | 0:a8fa94490a0a | 35 | */ |
gokmenascioglu | 0:a8fa94490a0a | 36 | class DirHandle { |
gokmenascioglu | 0:a8fa94490a0a | 37 | |
gokmenascioglu | 0:a8fa94490a0a | 38 | public: |
gokmenascioglu | 0:a8fa94490a0a | 39 | /* Function closedir |
gokmenascioglu | 0:a8fa94490a0a | 40 | * Closes the directory. |
gokmenascioglu | 0:a8fa94490a0a | 41 | * |
gokmenascioglu | 0:a8fa94490a0a | 42 | * Variables |
gokmenascioglu | 0:a8fa94490a0a | 43 | * returns - 0 on success, or -1 on error. |
gokmenascioglu | 0:a8fa94490a0a | 44 | */ |
gokmenascioglu | 0:a8fa94490a0a | 45 | virtual int closedir()=0; |
gokmenascioglu | 0:a8fa94490a0a | 46 | |
gokmenascioglu | 0:a8fa94490a0a | 47 | /* Function readdir |
gokmenascioglu | 0:a8fa94490a0a | 48 | * Return the directory entry at the current position, and |
gokmenascioglu | 0:a8fa94490a0a | 49 | * advances the position to the next entry. |
gokmenascioglu | 0:a8fa94490a0a | 50 | * |
gokmenascioglu | 0:a8fa94490a0a | 51 | * Returns |
gokmenascioglu | 0:a8fa94490a0a | 52 | * A pointer to a dirent structure representing the |
gokmenascioglu | 0:a8fa94490a0a | 53 | * directory entry at the current position, or NULL on reaching |
gokmenascioglu | 0:a8fa94490a0a | 54 | * end of directory or error. |
gokmenascioglu | 0:a8fa94490a0a | 55 | */ |
gokmenascioglu | 0:a8fa94490a0a | 56 | virtual struct dirent *readdir()=0; |
gokmenascioglu | 0:a8fa94490a0a | 57 | |
gokmenascioglu | 0:a8fa94490a0a | 58 | /* Function rewinddir |
gokmenascioglu | 0:a8fa94490a0a | 59 | * Resets the position to the beginning of the directory. |
gokmenascioglu | 0:a8fa94490a0a | 60 | */ |
gokmenascioglu | 0:a8fa94490a0a | 61 | virtual void rewinddir()=0; |
gokmenascioglu | 0:a8fa94490a0a | 62 | |
gokmenascioglu | 0:a8fa94490a0a | 63 | /* Function telldir |
gokmenascioglu | 0:a8fa94490a0a | 64 | * Returns the current position of the DirHandle. |
gokmenascioglu | 0:a8fa94490a0a | 65 | * |
gokmenascioglu | 0:a8fa94490a0a | 66 | * Returns |
gokmenascioglu | 0:a8fa94490a0a | 67 | * The current position, or -1 on error. |
gokmenascioglu | 0:a8fa94490a0a | 68 | */ |
gokmenascioglu | 0:a8fa94490a0a | 69 | virtual off_t telldir() { return -1; } |
gokmenascioglu | 0:a8fa94490a0a | 70 | |
gokmenascioglu | 0:a8fa94490a0a | 71 | /* Function seekdir |
gokmenascioglu | 0:a8fa94490a0a | 72 | * Sets the position of the DirHandle. |
gokmenascioglu | 0:a8fa94490a0a | 73 | * |
gokmenascioglu | 0:a8fa94490a0a | 74 | * Variables |
gokmenascioglu | 0:a8fa94490a0a | 75 | * location - The location to seek to. Must be a value returned |
gokmenascioglu | 0:a8fa94490a0a | 76 | * by telldir. |
gokmenascioglu | 0:a8fa94490a0a | 77 | */ |
gokmenascioglu | 0:a8fa94490a0a | 78 | virtual void seekdir(off_t location) { } |
gokmenascioglu | 0:a8fa94490a0a | 79 | |
gokmenascioglu | 0:a8fa94490a0a | 80 | }; |
gokmenascioglu | 0:a8fa94490a0a | 81 | |
gokmenascioglu | 0:a8fa94490a0a | 82 | } // namespace mbed |
gokmenascioglu | 0:a8fa94490a0a | 83 | |
gokmenascioglu | 0:a8fa94490a0a | 84 | typedef mbed::DirHandle DIR; |
gokmenascioglu | 0:a8fa94490a0a | 85 | |
gokmenascioglu | 0:a8fa94490a0a | 86 | extern "C" { |
gokmenascioglu | 0:a8fa94490a0a | 87 | DIR *opendir(const char*); |
gokmenascioglu | 0:a8fa94490a0a | 88 | struct dirent *readdir(DIR *); |
gokmenascioglu | 0:a8fa94490a0a | 89 | int closedir(DIR*); |
gokmenascioglu | 0:a8fa94490a0a | 90 | void rewinddir(DIR*); |
gokmenascioglu | 0:a8fa94490a0a | 91 | long telldir(DIR*); |
gokmenascioglu | 0:a8fa94490a0a | 92 | void seekdir(DIR*, long); |
gokmenascioglu | 0:a8fa94490a0a | 93 | int mkdir(const char *name, mode_t n); |
gokmenascioglu | 0:a8fa94490a0a | 94 | }; |
gokmenascioglu | 0:a8fa94490a0a | 95 | |
gokmenascioglu | 0:a8fa94490a0a | 96 | #endif /* MBED_DIRHANDLE_H */ |