Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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