Mangue Baja Box

Dependencies:   mbed

Committer:
einsteingustavo
Date:
Mon Jul 29 20:38:00 2019 +0000
Revision:
0:0dee8840a1c0
Mangue Baja Box

Who changed what in which revision?

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