mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
0:8024c367e29f
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

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