Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 00035 /** Represents a directory stream. Objects of this type are returned 00036 * by a FileSystemLike's opendir method. Implementations must define 00037 * at least closedir, readdir and rewinddir. 00038 * 00039 * If a FileSystemLike class defines the opendir method, then the 00040 * directories of an object of that type can be accessed by 00041 * DIR *d = opendir("/example/directory") (or opendir("/example") 00042 * to open the root of the filesystem), and then using readdir(d) etc. 00043 * 00044 * The root directory is considered to contain all FileLike and 00045 * FileSystemLike objects, so the DIR* returned by opendir("/") will 00046 * reflect this. 00047 * 00048 * @Note Synchronization level: Set by subclass 00049 */ 00050 class DirHandle { 00051 00052 public: 00053 /** Closes the directory. 00054 * 00055 * @returns 00056 * 0 on success, 00057 * -1 on error. 00058 */ 00059 virtual int closedir()=0; 00060 00061 /** Return the directory entry at the current position, and 00062 * advances the position to the next entry. 00063 * 00064 * @returns 00065 * A pointer to a dirent structure representing the 00066 * directory entry at the current position, or NULL on reaching 00067 * end of directory or error. 00068 */ 00069 virtual struct dirent *readdir()=0; 00070 00071 /** Resets the position to the beginning of the directory. 00072 */ 00073 virtual void rewinddir()=0; 00074 00075 /** Returns the current position of the DirHandle. 00076 * 00077 * @returns 00078 * the current position, 00079 * -1 on error. 00080 */ 00081 virtual off_t telldir() { return -1; } 00082 00083 /** Sets the position of the DirHandle. 00084 * 00085 * @param location The location to seek to. Must be a value returned by telldir. 00086 */ 00087 virtual void seekdir(off_t location) { (void)location;} 00088 00089 virtual ~DirHandle() {} 00090 00091 protected: 00092 00093 /** Acquire exclusive access to this object. 00094 */ 00095 virtual void lock() { 00096 // Stub 00097 } 00098 00099 /** Release exclusive access to this object. 00100 */ 00101 virtual void unlock() { 00102 // Stub 00103 } 00104 }; 00105 00106 } // namespace mbed 00107 00108 typedef mbed::DirHandle DIR; 00109 00110 extern "C" { 00111 DIR *opendir(const char*); 00112 struct dirent *readdir(DIR *); 00113 int closedir(DIR*); 00114 void rewinddir(DIR*); 00115 long telldir(DIR*); 00116 void seekdir(DIR*, long); 00117 int mkdir(const char *name, mode_t n); 00118 }; 00119 00120 #endif /* MBED_DIRHANDLE_H */
Generated on Tue Jul 12 2022 22:19:20 by
