initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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