mbed library sources

Dependents:   FRDM-KL46Z_LCD_Test FRDM-KL46Z_LCD_Test FRDM-KL46Z_Plantilla FRDM-KL46Z_Plantilla ... more

Committer:
ebrus
Date:
Thu Jul 28 15:56:34 2016 +0000
Revision:
0:6bc4ac881c8e
1;

Who changed what in which revision?

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