mbed library sources. Supersedes mbed-src.

Fork of mbed by teralytic

Committer:
rodriguise
Date:
Mon Oct 17 18:47:01 2016 +0000
Revision:
148:4802eb17e82b
Parent:
144:ef7eb2e8f9f7
backup

Who changed what in which revision?

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