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.
Fork of mbed-src by
FileSystemLike.cpp
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 #include "FileSystemLike.h" 00017 00018 namespace mbed { 00019 00020 class BaseDirHandle : public DirHandle { 00021 public: 00022 /* 00023 We keep track of our current location as the n'th object in the 00024 FileSystemLike list. Using a Base* instead would cause problems if that 00025 object were to be destroyed between readdirs. 00026 Using this method does mean though that destroying/creating objects can 00027 give unusual results from readdir. 00028 */ 00029 off_t n; 00030 struct dirent cur_entry; 00031 00032 BaseDirHandle() { 00033 n = 0; 00034 } 00035 00036 virtual int closedir() { 00037 delete this; 00038 return 0; 00039 } 00040 00041 virtual struct dirent *readdir() { 00042 FileBase *ptr = FileBase::get(n); 00043 if (ptr == NULL) return NULL; 00044 00045 /* Increment n, so next readdir gets the next item */ 00046 n++; 00047 00048 /* Setup cur entry and return a pointer to it */ 00049 std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX); 00050 return &cur_entry; 00051 } 00052 00053 virtual off_t telldir() { 00054 return n; 00055 } 00056 00057 virtual void seekdir(off_t offset) { 00058 n = offset; 00059 } 00060 00061 virtual void rewinddir() { 00062 n = 0; 00063 } 00064 }; 00065 00066 FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) { 00067 00068 } 00069 00070 FileSystemLike::~FileSystemLike() { 00071 00072 } 00073 00074 DirHandle *FileSystemLike::opendir() { 00075 return new BaseDirHandle(); 00076 } 00077 00078 } // namespace mbed
Generated on Tue Jul 12 2022 21:21:33 by
