1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "FileSystemLike.h"
20 class BaseDirHandle : public DirHandle {
23 We keep track of our current location as the n'th object in the
24 FileSystemLike list. Using a Base* instead would cause problems if that
25 object were to be destroyed between readdirs.
26 Using this method does mean though that destroying/creating objects can
27 give unusual results from readdir.
30 struct dirent cur_entry;
32 BaseDirHandle() : n(0), cur_entry() {
35 virtual int closedir() {
40 virtual struct dirent *readdir() {
41 FileBase *ptr = FileBase::get(n);
42 if (ptr == NULL) return NULL;
44 /* Increment n, so next readdir gets the next item */
47 /* Setup cur entry and return a pointer to it */
48 std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX);
52 virtual off_t telldir() {
56 virtual void seekdir(off_t offset) {
60 virtual void rewinddir() {
65 FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) {
69 FileSystemLike::~FileSystemLike() {
73 DirHandle *FileSystemLike::opendir() {
74 return new BaseDirHandle();