lib
Fork of mbed-dev by
Embed:
(wiki syntax)
Show/hide line numbers
DirHandle.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef MBED_DIRHANDLE_H 00017 #define MBED_DIRHANDLE_H 00018 00019 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00020 # define NAME_MAX 255 00021 typedef int mode_t; 00022 00023 #else 00024 # include <sys/syslimits.h> 00025 #endif 00026 00027 #include "FileHandle.h" 00028 00029 struct dirent { 00030 char d_name[NAME_MAX+1]; 00031 }; 00032 00033 namespace mbed { 00034 /** \addtogroup drivers */ 00035 /** @{*/ 00036 00037 /** Represents a directory stream. Objects of this type are returned 00038 * by a FileSystemLike's opendir method. Implementations must define 00039 * at least closedir, readdir and rewinddir. 00040 * 00041 * If a FileSystemLike class defines the opendir method, then the 00042 * directories of an object of that type can be accessed by 00043 * DIR *d = opendir("/example/directory") (or opendir("/example") 00044 * to open the root of the filesystem), and then using readdir(d) etc. 00045 * 00046 * The root directory is considered to contain all FileLike and 00047 * FileSystemLike objects, so the DIR* returned by opendir("/") will 00048 * reflect this. 00049 * 00050 * @Note Synchronization level: Set by subclass 00051 */ 00052 class DirHandle { 00053 00054 public: 00055 /** Closes the directory. 00056 * 00057 * @returns 00058 * 0 on success, 00059 * -1 on error. 00060 */ 00061 virtual int closedir()=0; 00062 00063 /** Return the directory entry at the current position, and 00064 * advances the position to the next entry. 00065 * 00066 * @returns 00067 * A pointer to a dirent structure representing the 00068 * directory entry at the current position, or NULL on reaching 00069 * end of directory or error. 00070 */ 00071 virtual struct dirent *readdir()=0; 00072 00073 /** Resets the position to the beginning of the directory. 00074 */ 00075 virtual void rewinddir()=0; 00076 00077 /** Returns the current position of the DirHandle. 00078 * 00079 * @returns 00080 * the current position, 00081 * -1 on error. 00082 */ 00083 virtual off_t telldir() { return -1; } 00084 00085 /** Sets the position of the DirHandle. 00086 * 00087 * @param location The location to seek to. Must be a value returned by telldir. 00088 */ 00089 virtual void seekdir(off_t location) { (void)location;} 00090 00091 virtual ~DirHandle() {} 00092 00093 protected: 00094 00095 /** Acquire exclusive access to this object. 00096 */ 00097 virtual void lock() { 00098 // Stub 00099 } 00100 00101 /** Release exclusive access to this object. 00102 */ 00103 virtual void unlock() { 00104 // Stub 00105 } 00106 }; 00107 00108 } // namespace mbed 00109 00110 typedef mbed::DirHandle DIR; 00111 00112 extern "C" { 00113 DIR *opendir(const char*); 00114 struct dirent *readdir(DIR *); 00115 int closedir(DIR*); 00116 void rewinddir(DIR*); 00117 long telldir(DIR*); 00118 void seekdir(DIR*, long); 00119 int mkdir(const char *name, mode_t n); 00120 }; 00121 00122 #endif /* MBED_DIRHANDLE_H */ 00123 00124 /** @}*/
Generated on Tue Jul 12 2022 20:00:14 by 1.7.2