mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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