mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

UserRevisionLine numberNew contents of line
modtronix 1:71204b8406f2 1 /* mbed Microcontroller Library
modtronix 1:71204b8406f2 2 * Copyright (c) 2006-2013 ARM Limited
modtronix 1:71204b8406f2 3 *
modtronix 1:71204b8406f2 4 * Licensed under the Apache License, Version 2.0 (the "License");
modtronix 1:71204b8406f2 5 * you may not use this file except in compliance with the License.
modtronix 1:71204b8406f2 6 * You may obtain a copy of the License at
modtronix 1:71204b8406f2 7 *
modtronix 1:71204b8406f2 8 * http://www.apache.org/licenses/LICENSE-2.0
modtronix 1:71204b8406f2 9 *
modtronix 1:71204b8406f2 10 * Unless required by applicable law or agreed to in writing, software
modtronix 1:71204b8406f2 11 * distributed under the License is distributed on an "AS IS" BASIS,
modtronix 1:71204b8406f2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
modtronix 1:71204b8406f2 13 * See the License for the specific language governing permissions and
modtronix 1:71204b8406f2 14 * limitations under the License.
modtronix 1:71204b8406f2 15 */
modtronix 1:71204b8406f2 16 #include "FileSystemLike.h"
modtronix 1:71204b8406f2 17
modtronix 1:71204b8406f2 18 namespace mbed {
modtronix 1:71204b8406f2 19
modtronix 1:71204b8406f2 20 class BaseDirHandle : public DirHandle {
modtronix 1:71204b8406f2 21 public:
modtronix 1:71204b8406f2 22 /*
modtronix 1:71204b8406f2 23 We keep track of our current location as the n'th object in the
modtronix 1:71204b8406f2 24 FileSystemLike list. Using a Base* instead would cause problems if that
modtronix 1:71204b8406f2 25 object were to be destroyed between readdirs.
modtronix 1:71204b8406f2 26 Using this method does mean though that destroying/creating objects can
modtronix 1:71204b8406f2 27 give unusual results from readdir.
modtronix 1:71204b8406f2 28 */
modtronix 1:71204b8406f2 29 off_t n;
modtronix 1:71204b8406f2 30 struct dirent cur_entry;
modtronix 1:71204b8406f2 31
modtronix 1:71204b8406f2 32 BaseDirHandle() : n(0), cur_entry() {
modtronix 1:71204b8406f2 33 }
modtronix 1:71204b8406f2 34
modtronix 1:71204b8406f2 35 virtual int closedir() {
modtronix 1:71204b8406f2 36 delete this;
modtronix 1:71204b8406f2 37 return 0;
modtronix 1:71204b8406f2 38 }
modtronix 1:71204b8406f2 39
modtronix 1:71204b8406f2 40 virtual struct dirent *readdir() {
modtronix 1:71204b8406f2 41 FileBase *ptr = FileBase::get(n);
modtronix 1:71204b8406f2 42 if (ptr == NULL) return NULL;
modtronix 1:71204b8406f2 43
modtronix 1:71204b8406f2 44 /* Increment n, so next readdir gets the next item */
modtronix 1:71204b8406f2 45 n++;
modtronix 1:71204b8406f2 46
modtronix 1:71204b8406f2 47 /* Setup cur entry and return a pointer to it */
modtronix 1:71204b8406f2 48 std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX);
modtronix 1:71204b8406f2 49 return &cur_entry;
modtronix 1:71204b8406f2 50 }
modtronix 1:71204b8406f2 51
modtronix 1:71204b8406f2 52 virtual off_t telldir() {
modtronix 1:71204b8406f2 53 return n;
modtronix 1:71204b8406f2 54 }
modtronix 1:71204b8406f2 55
modtronix 1:71204b8406f2 56 virtual void seekdir(off_t offset) {
modtronix 1:71204b8406f2 57 n = offset;
modtronix 1:71204b8406f2 58 }
modtronix 1:71204b8406f2 59
modtronix 1:71204b8406f2 60 virtual void rewinddir() {
modtronix 1:71204b8406f2 61 n = 0;
modtronix 1:71204b8406f2 62 }
modtronix 1:71204b8406f2 63 };
modtronix 1:71204b8406f2 64
modtronix 1:71204b8406f2 65 FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) {
modtronix 1:71204b8406f2 66
modtronix 1:71204b8406f2 67 }
modtronix 1:71204b8406f2 68
modtronix 1:71204b8406f2 69 FileSystemLike::~FileSystemLike() {
modtronix 1:71204b8406f2 70
modtronix 1:71204b8406f2 71 }
modtronix 1:71204b8406f2 72
modtronix 1:71204b8406f2 73 DirHandle *FileSystemLike::opendir() {
modtronix 1:71204b8406f2 74 return new BaseDirHandle();
modtronix 1:71204b8406f2 75 }
modtronix 1:71204b8406f2 76
modtronix 1:71204b8406f2 77 } // namespace mbed