test

Dependents:   robotic_fish_7

Committer:
juansal12
Date:
Tue Jan 14 19:14:29 2020 +0000
Revision:
0:44931ff4a3ed
Sofi 7 code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
juansal12 0:44931ff4a3ed 1 /* mbed Microcontroller Library
juansal12 0:44931ff4a3ed 2 * Copyright (c) 2006-2013 ARM Limited
juansal12 0:44931ff4a3ed 3 *
juansal12 0:44931ff4a3ed 4 * Licensed under the Apache License, Version 2.0 (the "License");
juansal12 0:44931ff4a3ed 5 * you may not use this file except in compliance with the License.
juansal12 0:44931ff4a3ed 6 * You may obtain a copy of the License at
juansal12 0:44931ff4a3ed 7 *
juansal12 0:44931ff4a3ed 8 * http://www.apache.org/licenses/LICENSE-2.0
juansal12 0:44931ff4a3ed 9 *
juansal12 0:44931ff4a3ed 10 * Unless required by applicable law or agreed to in writing, software
juansal12 0:44931ff4a3ed 11 * distributed under the License is distributed on an "AS IS" BASIS,
juansal12 0:44931ff4a3ed 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
juansal12 0:44931ff4a3ed 13 * See the License for the specific language governing permissions and
juansal12 0:44931ff4a3ed 14 * limitations under the License.
juansal12 0:44931ff4a3ed 15 */
juansal12 0:44931ff4a3ed 16 #ifndef MBED_DIRHANDLE_H
juansal12 0:44931ff4a3ed 17 #define MBED_DIRHANDLE_H
juansal12 0:44931ff4a3ed 18
juansal12 0:44931ff4a3ed 19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
juansal12 0:44931ff4a3ed 20 # define NAME_MAX 255
juansal12 0:44931ff4a3ed 21 typedef int mode_t;
juansal12 0:44931ff4a3ed 22
juansal12 0:44931ff4a3ed 23 #else
juansal12 0:44931ff4a3ed 24 # include <sys/syslimits.h>
juansal12 0:44931ff4a3ed 25 #endif
juansal12 0:44931ff4a3ed 26
juansal12 0:44931ff4a3ed 27 #include "FileHandle.h"
juansal12 0:44931ff4a3ed 28
juansal12 0:44931ff4a3ed 29 struct dirent {
juansal12 0:44931ff4a3ed 30 char d_name[NAME_MAX+1];
juansal12 0:44931ff4a3ed 31 };
juansal12 0:44931ff4a3ed 32
juansal12 0:44931ff4a3ed 33 namespace mbed {
juansal12 0:44931ff4a3ed 34
juansal12 0:44931ff4a3ed 35 /** Represents a directory stream. Objects of this type are returned
juansal12 0:44931ff4a3ed 36 * by a FileSystemLike's opendir method. Implementations must define
juansal12 0:44931ff4a3ed 37 * at least closedir, readdir and rewinddir.
juansal12 0:44931ff4a3ed 38 *
juansal12 0:44931ff4a3ed 39 * If a FileSystemLike class defines the opendir method, then the
juansal12 0:44931ff4a3ed 40 * directories of an object of that type can be accessed by
juansal12 0:44931ff4a3ed 41 * DIR *d = opendir("/example/directory") (or opendir("/example")
juansal12 0:44931ff4a3ed 42 * to open the root of the filesystem), and then using readdir(d) etc.
juansal12 0:44931ff4a3ed 43 *
juansal12 0:44931ff4a3ed 44 * The root directory is considered to contain all FileLike and
juansal12 0:44931ff4a3ed 45 * FileSystemLike objects, so the DIR* returned by opendir("/") will
juansal12 0:44931ff4a3ed 46 * reflect this.
juansal12 0:44931ff4a3ed 47 */
juansal12 0:44931ff4a3ed 48 class DirHandle {
juansal12 0:44931ff4a3ed 49
juansal12 0:44931ff4a3ed 50 public:
juansal12 0:44931ff4a3ed 51 /** Closes the directory.
juansal12 0:44931ff4a3ed 52 *
juansal12 0:44931ff4a3ed 53 * @returns
juansal12 0:44931ff4a3ed 54 * 0 on success,
juansal12 0:44931ff4a3ed 55 * -1 on error.
juansal12 0:44931ff4a3ed 56 */
juansal12 0:44931ff4a3ed 57 virtual int closedir()=0;
juansal12 0:44931ff4a3ed 58
juansal12 0:44931ff4a3ed 59 /** Return the directory entry at the current position, and
juansal12 0:44931ff4a3ed 60 * advances the position to the next entry.
juansal12 0:44931ff4a3ed 61 *
juansal12 0:44931ff4a3ed 62 * @returns
juansal12 0:44931ff4a3ed 63 * A pointer to a dirent structure representing the
juansal12 0:44931ff4a3ed 64 * directory entry at the current position, or NULL on reaching
juansal12 0:44931ff4a3ed 65 * end of directory or error.
juansal12 0:44931ff4a3ed 66 */
juansal12 0:44931ff4a3ed 67 virtual struct dirent *readdir()=0;
juansal12 0:44931ff4a3ed 68
juansal12 0:44931ff4a3ed 69 /** Resets the position to the beginning of the directory.
juansal12 0:44931ff4a3ed 70 */
juansal12 0:44931ff4a3ed 71 virtual void rewinddir()=0;
juansal12 0:44931ff4a3ed 72
juansal12 0:44931ff4a3ed 73 /** Returns the current position of the DirHandle.
juansal12 0:44931ff4a3ed 74 *
juansal12 0:44931ff4a3ed 75 * @returns
juansal12 0:44931ff4a3ed 76 * the current position,
juansal12 0:44931ff4a3ed 77 * -1 on error.
juansal12 0:44931ff4a3ed 78 */
juansal12 0:44931ff4a3ed 79 virtual off_t telldir() { return -1; }
juansal12 0:44931ff4a3ed 80
juansal12 0:44931ff4a3ed 81 /** Sets the position of the DirHandle.
juansal12 0:44931ff4a3ed 82 *
juansal12 0:44931ff4a3ed 83 * @param location The location to seek to. Must be a value returned by telldir.
juansal12 0:44931ff4a3ed 84 */
juansal12 0:44931ff4a3ed 85 virtual void seekdir(off_t location) { }
juansal12 0:44931ff4a3ed 86
juansal12 0:44931ff4a3ed 87 virtual ~DirHandle() {}
juansal12 0:44931ff4a3ed 88 };
juansal12 0:44931ff4a3ed 89
juansal12 0:44931ff4a3ed 90 } // namespace mbed
juansal12 0:44931ff4a3ed 91
juansal12 0:44931ff4a3ed 92 typedef mbed::DirHandle DIR;
juansal12 0:44931ff4a3ed 93
juansal12 0:44931ff4a3ed 94 extern "C" {
juansal12 0:44931ff4a3ed 95 DIR *opendir(const char*);
juansal12 0:44931ff4a3ed 96 struct dirent *readdir(DIR *);
juansal12 0:44931ff4a3ed 97 int closedir(DIR*);
juansal12 0:44931ff4a3ed 98 void rewinddir(DIR*);
juansal12 0:44931ff4a3ed 99 long telldir(DIR*);
juansal12 0:44931ff4a3ed 100 void seekdir(DIR*, long);
juansal12 0:44931ff4a3ed 101 int mkdir(const char *name, mode_t n);
juansal12 0:44931ff4a3ed 102 };
juansal12 0:44931ff4a3ed 103
juansal12 0:44931ff4a3ed 104 #endif /* MBED_DIRHANDLE_H */