mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Oct 05 09:16:41 2012 +0000
Revision:
0:8024c367e29f
Child:
8:c14af7958ef5
First release of the mbed libraries for KL25Z

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:8024c367e29f 1 /* mbed Microcontroller Library - DirHandler
emilmont 0:8024c367e29f 2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
emilmont 0:8024c367e29f 3 */
emilmont 0:8024c367e29f 4
emilmont 0:8024c367e29f 5 #ifndef MBED_DIRHANDLE_H
emilmont 0:8024c367e29f 6 #define MBED_DIRHANDLE_H
emilmont 0:8024c367e29f 7
emilmont 0:8024c367e29f 8 #ifdef __ARMCC_VERSION
emilmont 0:8024c367e29f 9 # define NAME_MAX 255
emilmont 0:8024c367e29f 10 typedef int mode_t;
emilmont 0:8024c367e29f 11 #else
emilmont 0:8024c367e29f 12 # include <sys/syslimits.h>
emilmont 0:8024c367e29f 13 #endif
emilmont 0:8024c367e29f 14 #include "FileHandle.h"
emilmont 0:8024c367e29f 15
emilmont 0:8024c367e29f 16 struct dirent {
emilmont 0:8024c367e29f 17 char d_name[NAME_MAX+1];
emilmont 0:8024c367e29f 18 };
emilmont 0:8024c367e29f 19
emilmont 0:8024c367e29f 20 namespace mbed {
emilmont 0:8024c367e29f 21
emilmont 0:8024c367e29f 22 /* Class DirHandle
emilmont 0:8024c367e29f 23 * Represents a directory stream. Objects of this type are returned
emilmont 0:8024c367e29f 24 * by a FileSystemLike's opendir method. Implementations must define
emilmont 0:8024c367e29f 25 * at least closedir, readdir and rewinddir.
emilmont 0:8024c367e29f 26 *
emilmont 0:8024c367e29f 27 * If a FileSystemLike class defines the opendir method, then the
emilmont 0:8024c367e29f 28 * directories of an object of that type can be accessed by
emilmont 0:8024c367e29f 29 * DIR *d = opendir("/example/directory") (or opendir("/example")
emilmont 0:8024c367e29f 30 * to open the root of the filesystem), and then using readdir(d) etc.
emilmont 0:8024c367e29f 31 *
emilmont 0:8024c367e29f 32 * The root directory is considered to contain all FileLike and
emilmont 0:8024c367e29f 33 * FileSystemLike objects, so the DIR* returned by opendir("/") will
emilmont 0:8024c367e29f 34 * reflect this.
emilmont 0:8024c367e29f 35 */
emilmont 0:8024c367e29f 36 class DirHandle {
emilmont 0:8024c367e29f 37
emilmont 0:8024c367e29f 38 public:
emilmont 0:8024c367e29f 39 /* Function closedir
emilmont 0:8024c367e29f 40 * Closes the directory.
emilmont 0:8024c367e29f 41 *
emilmont 0:8024c367e29f 42 * Variables
emilmont 0:8024c367e29f 43 * returns - 0 on success, or -1 on error.
emilmont 0:8024c367e29f 44 */
emilmont 0:8024c367e29f 45 virtual int closedir()=0;
emilmont 0:8024c367e29f 46
emilmont 0:8024c367e29f 47 /* Function readdir
emilmont 0:8024c367e29f 48 * Return the directory entry at the current position, and
emilmont 0:8024c367e29f 49 * advances the position to the next entry.
emilmont 0:8024c367e29f 50 *
emilmont 0:8024c367e29f 51 * Returns
emilmont 0:8024c367e29f 52 * A pointer to a dirent structure representing the
emilmont 0:8024c367e29f 53 * directory entry at the current position, or NULL on reaching
emilmont 0:8024c367e29f 54 * end of directory or error.
emilmont 0:8024c367e29f 55 */
emilmont 0:8024c367e29f 56 virtual struct dirent *readdir()=0;
emilmont 0:8024c367e29f 57
emilmont 0:8024c367e29f 58 /* Function rewinddir
emilmont 0:8024c367e29f 59 * Resets the position to the beginning of the directory.
emilmont 0:8024c367e29f 60 */
emilmont 0:8024c367e29f 61 virtual void rewinddir()=0;
emilmont 0:8024c367e29f 62
emilmont 0:8024c367e29f 63 /* Function telldir
emilmont 0:8024c367e29f 64 * Returns the current position of the DirHandle.
emilmont 0:8024c367e29f 65 *
emilmont 0:8024c367e29f 66 * Returns
emilmont 0:8024c367e29f 67 * The current position, or -1 on error.
emilmont 0:8024c367e29f 68 */
emilmont 0:8024c367e29f 69 virtual off_t telldir() { return -1; }
emilmont 0:8024c367e29f 70
emilmont 0:8024c367e29f 71 /* Function seekdir
emilmont 0:8024c367e29f 72 * Sets the position of the DirHandle.
emilmont 0:8024c367e29f 73 *
emilmont 0:8024c367e29f 74 * Variables
emilmont 0:8024c367e29f 75 * location - The location to seek to. Must be a value returned
emilmont 0:8024c367e29f 76 * by telldir.
emilmont 0:8024c367e29f 77 */
emilmont 0:8024c367e29f 78 virtual void seekdir(off_t location) { }
emilmont 0:8024c367e29f 79
emilmont 0:8024c367e29f 80 };
emilmont 0:8024c367e29f 81
emilmont 0:8024c367e29f 82 } // namespace mbed
emilmont 0:8024c367e29f 83
emilmont 0:8024c367e29f 84 typedef mbed::DirHandle DIR;
emilmont 0:8024c367e29f 85
emilmont 0:8024c367e29f 86 extern "C" {
emilmont 0:8024c367e29f 87 DIR *opendir(const char*);
emilmont 0:8024c367e29f 88 struct dirent *readdir(DIR *);
emilmont 0:8024c367e29f 89 int closedir(DIR*);
emilmont 0:8024c367e29f 90 void rewinddir(DIR*);
emilmont 0:8024c367e29f 91 long telldir(DIR*);
emilmont 0:8024c367e29f 92 void seekdir(DIR*, long);
emilmont 0:8024c367e29f 93 int mkdir(const char *name, mode_t n);
emilmont 0:8024c367e29f 94 };
emilmont 0:8024c367e29f 95
emilmont 0:8024c367e29f 96 #endif /* MBED_DIRHANDLE_H */