test
platform/FileSystemLike.h@2:4364577b5ad8, 2020-11-09 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Nov 09 00:33:19 2020 -0500
- Revision:
- 2:4364577b5ad8
- Parent:
- 1:8a094db1347f
copied mbed library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elijahsj | 1:8a094db1347f | 1 | /* mbed Microcontroller Library |
elijahsj | 1:8a094db1347f | 2 | * Copyright (c) 2006-2013 ARM Limited |
elijahsj | 1:8a094db1347f | 3 | * |
elijahsj | 1:8a094db1347f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elijahsj | 1:8a094db1347f | 5 | * you may not use this file except in compliance with the License. |
elijahsj | 1:8a094db1347f | 6 | * You may obtain a copy of the License at |
elijahsj | 1:8a094db1347f | 7 | * |
elijahsj | 1:8a094db1347f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elijahsj | 1:8a094db1347f | 9 | * |
elijahsj | 1:8a094db1347f | 10 | * Unless required by applicable law or agreed to in writing, software |
elijahsj | 1:8a094db1347f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elijahsj | 1:8a094db1347f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elijahsj | 1:8a094db1347f | 13 | * See the License for the specific language governing permissions and |
elijahsj | 1:8a094db1347f | 14 | * limitations under the License. |
elijahsj | 1:8a094db1347f | 15 | */ |
elijahsj | 1:8a094db1347f | 16 | #ifndef MBED_FILESYSTEMLIKE_H |
elijahsj | 1:8a094db1347f | 17 | #define MBED_FILESYSTEMLIKE_H |
elijahsj | 1:8a094db1347f | 18 | |
elijahsj | 1:8a094db1347f | 19 | #include "platform/platform.h" |
elijahsj | 1:8a094db1347f | 20 | |
elijahsj | 1:8a094db1347f | 21 | #include "platform/FileSystemHandle.h" |
elijahsj | 1:8a094db1347f | 22 | #include "platform/FileHandle.h" |
elijahsj | 1:8a094db1347f | 23 | #include "platform/DirHandle.h" |
elijahsj | 1:8a094db1347f | 24 | #include "platform/NonCopyable.h" |
elijahsj | 1:8a094db1347f | 25 | |
elijahsj | 1:8a094db1347f | 26 | namespace mbed { |
elijahsj | 1:8a094db1347f | 27 | /** \addtogroup platform */ |
elijahsj | 1:8a094db1347f | 28 | |
elijahsj | 1:8a094db1347f | 29 | |
elijahsj | 1:8a094db1347f | 30 | /** A filesystem-like object is one that can be used to open file-like |
elijahsj | 1:8a094db1347f | 31 | * objects though it by fopen("/name/filename", mode) |
elijahsj | 1:8a094db1347f | 32 | * |
elijahsj | 1:8a094db1347f | 33 | * Implementations must define at least open (the default definitions |
elijahsj | 1:8a094db1347f | 34 | * of the rest of the functions just return error values). |
elijahsj | 1:8a094db1347f | 35 | * |
elijahsj | 1:8a094db1347f | 36 | * @note Synchronization level: Set by subclass |
elijahsj | 1:8a094db1347f | 37 | * @ingroup platform |
elijahsj | 1:8a094db1347f | 38 | */ |
elijahsj | 1:8a094db1347f | 39 | class FileSystemLike : public FileSystemHandle, public FileBase, private NonCopyable<FileSystemLike> { |
elijahsj | 1:8a094db1347f | 40 | public: |
elijahsj | 1:8a094db1347f | 41 | /** FileSystemLike lifetime |
elijahsj | 1:8a094db1347f | 42 | */ |
elijahsj | 1:8a094db1347f | 43 | FileSystemLike(const char *name = NULL) : FileBase(name, FileSystemPathType) {} |
elijahsj | 1:8a094db1347f | 44 | virtual ~FileSystemLike() {} |
elijahsj | 1:8a094db1347f | 45 | |
elijahsj | 1:8a094db1347f | 46 | // Inherited functions with name conflicts |
elijahsj | 1:8a094db1347f | 47 | using FileSystemHandle::open; |
elijahsj | 1:8a094db1347f | 48 | |
elijahsj | 1:8a094db1347f | 49 | /** Open a file on the filesystem |
elijahsj | 1:8a094db1347f | 50 | * |
elijahsj | 1:8a094db1347f | 51 | * @param path The name of the file to open |
elijahsj | 1:8a094db1347f | 52 | * @param flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, |
elijahsj | 1:8a094db1347f | 53 | * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND |
elijahsj | 1:8a094db1347f | 54 | * @return A file handle on success, NULL on failure |
elijahsj | 1:8a094db1347f | 55 | * @deprecated Replaced by `int open(FileHandle **, ...)` for propagating error codes |
elijahsj | 1:8a094db1347f | 56 | */ |
elijahsj | 1:8a094db1347f | 57 | MBED_DEPRECATED_SINCE("mbed-os-5.5", |
elijahsj | 1:8a094db1347f | 58 | "Replaced by `int open(FileHandle **, ...)` for propagating error codes") |
elijahsj | 1:8a094db1347f | 59 | FileHandle *open(const char *path, int flags) |
elijahsj | 1:8a094db1347f | 60 | { |
elijahsj | 1:8a094db1347f | 61 | FileHandle *file; |
elijahsj | 1:8a094db1347f | 62 | int err = open(&file, path, flags); |
elijahsj | 1:8a094db1347f | 63 | return err ? NULL : file; |
elijahsj | 1:8a094db1347f | 64 | } |
elijahsj | 1:8a094db1347f | 65 | |
elijahsj | 1:8a094db1347f | 66 | /** Open a directory on the filesystem |
elijahsj | 1:8a094db1347f | 67 | * |
elijahsj | 1:8a094db1347f | 68 | * @param path Name of the directory to open |
elijahsj | 1:8a094db1347f | 69 | * @return A directory handle on success, NULL on failure |
elijahsj | 1:8a094db1347f | 70 | * @deprecated Replaced by `int open(DirHandle **, ...)` for propagating error codes |
elijahsj | 1:8a094db1347f | 71 | */ |
elijahsj | 1:8a094db1347f | 72 | MBED_DEPRECATED_SINCE("mbed-os-5.5", |
elijahsj | 1:8a094db1347f | 73 | "Replaced by `int open(DirHandle **, ...)` for propagating error codes") |
elijahsj | 1:8a094db1347f | 74 | DirHandle *opendir(const char *path) |
elijahsj | 1:8a094db1347f | 75 | { |
elijahsj | 1:8a094db1347f | 76 | DirHandle *dir; |
elijahsj | 1:8a094db1347f | 77 | int err = open(&dir, path); |
elijahsj | 1:8a094db1347f | 78 | return err ? NULL : dir; |
elijahsj | 1:8a094db1347f | 79 | } |
elijahsj | 1:8a094db1347f | 80 | }; |
elijahsj | 1:8a094db1347f | 81 | |
elijahsj | 1:8a094db1347f | 82 | |
elijahsj | 1:8a094db1347f | 83 | } // namespace mbed |
elijahsj | 1:8a094db1347f | 84 | |
elijahsj | 1:8a094db1347f | 85 | #endif |