SPKT

Dependents:   Player

Committer:
phungductung
Date:
Tue Jun 04 21:51:46 2019 +0000
Revision:
0:e87aa4c49e95
libray

Who changed what in which revision?

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