SHIO

Fork of mbed-stm32l0/l1-src by lzbp li

Committer:
lzbpli
Date:
Thu Sep 08 02:46:37 2016 +0000
Revision:
638:56887a2974b9
Parent:
13:0645d8841f51
????

Who changed what in which revision?

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