printer

Dependents:   Good_Serial_HelloWorld_Mbed

Fork of mbed by gokmen ascioglu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DirHandle.h Source File

DirHandle.h

00001 /* mbed Microcontroller Library - DirHandler
00002  * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
00003  */ 
00004  
00005 #ifndef MBED_DIRHANDLE_H
00006 #define MBED_DIRHANDLE_H
00007 
00008 #ifdef __ARMCC_VERSION
00009 # define NAME_MAX 255
00010 typedef int mode_t;
00011 #else
00012 # include <sys/syslimits.h>
00013 #endif
00014 #include "FileHandle.h"
00015 
00016 struct dirent {
00017     char d_name[NAME_MAX+1];
00018 };
00019 
00020 namespace mbed {
00021 
00022 /* Class DirHandle
00023  *  Represents a directory stream. Objects of this type are returned
00024  *  by a FileSystemLike's opendir method. Implementations must define
00025  *  at least closedir, readdir and rewinddir.
00026  *
00027  *  If a FileSystemLike class defines the opendir method, then the
00028  *  directories of an object of that type can be accessed by 
00029  *  DIR *d = opendir("/example/directory") (or opendir("/example") 
00030  *  to open the root of the filesystem), and then using readdir(d) etc.
00031  *
00032  *  The root directory is considered to contain all FileLike and
00033  *  FileSystemLike objects, so the DIR* returned by opendir("/") will
00034  *  reflect this.
00035  */
00036 class DirHandle {
00037 
00038  public:
00039     /* Function closedir
00040      *  Closes the directory.
00041      *
00042      * Variables
00043      *  returns - 0 on success, or -1 on error.
00044      */
00045     virtual int closedir()=0;
00046 
00047     /* Function readdir
00048      *  Return the directory entry at the current position, and
00049      *  advances the position to the next entry.
00050      *
00051      * Returns
00052      *  A pointer to a dirent structure representing the
00053      *  directory entry at the current position, or NULL on reaching
00054      *  end of directory or error.
00055      */
00056     virtual struct dirent *readdir()=0;
00057 
00058     /* Function rewinddir
00059      *  Resets the position to the beginning of the directory.
00060      */
00061     virtual void rewinddir()=0;
00062 
00063     /* Function telldir
00064      *  Returns the current position of the DirHandle.
00065      *
00066      * Returns
00067      *  The current position, or -1 on error.
00068      */
00069     virtual off_t telldir() { return -1; }
00070 
00071     /* Function seekdir
00072      *  Sets the position of the DirHandle.
00073      *
00074      * Variables
00075      *  location - The location to seek to. Must be a value returned
00076      *   by telldir.
00077      */
00078     virtual void seekdir(off_t location) { }
00079 
00080 };
00081 
00082 } // namespace mbed
00083 
00084 typedef mbed::DirHandle DIR;
00085 
00086 extern "C" {
00087     DIR *opendir(const char*);
00088     struct dirent *readdir(DIR *);
00089     int closedir(DIR*);
00090     void rewinddir(DIR*);
00091     long telldir(DIR*);
00092     void seekdir(DIR*, long);
00093     int mkdir(const char *name, mode_t n);
00094 };
00095 
00096 #endif /* MBED_DIRHANDLE_H */