The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
drivers/FileLike.h@140:97feb9bacc10, 2017-04-12 (annotated)
- Committer:
- <>
- Date:
- Wed Apr 12 16:07:08 2017 +0100
- Revision:
- 140:97feb9bacc10
- Parent:
- 138:093f2bd7b9eb
Release 140 of the mbed library
Ports for Upcoming Targets
3841: Add nRf52840 target https://github.com/ARMmbed/mbed-os/pull/3841
3992: Introducing UBLOX_C030 platform. https://github.com/ARMmbed/mbed-os/pull/3992
Fixes and Changes
3951: [NUCLEO_F303ZE] Correct ARDUINO pin https://github.com/ARMmbed/mbed-os/pull/3951
4021: Fixing a macro to detect when RTOS was in use for the NRF52840_DK https://github.com/ARMmbed/mbed-os/pull/4021
3979: KW24D: Add missing SPI defines and Arduino connector definitions https://github.com/ARMmbed/mbed-os/pull/3979
3990: UBLOX_C027: construct a ticker-based wait, rather than calling wait_ms(), in the https://github.com/ARMmbed/mbed-os/pull/3990
4003: Fixed OBOE in async serial tx for NRF52 target, fixes #4002 https://github.com/ARMmbed/mbed-os/pull/4003
4012: STM32: Correct I2C master error handling https://github.com/ARMmbed/mbed-os/pull/4012
4020: NUCLEO_L011K4 remove unsupported tool chain files https://github.com/ARMmbed/mbed-os/pull/4020
4065: K66F: Move bss section to m_data_2 Section https://github.com/ARMmbed/mbed-os/pull/4065
4014: Issue 3763: Reduce heap allocation in the GCC linker file https://github.com/ARMmbed/mbed-os/pull/4014
4030: [STM32L0] reduce IAR heap and stack size for small targets https://github.com/ARMmbed/mbed-os/pull/4030
4109: NUCLEO_L476RG : minor serial pin update https://github.com/ARMmbed/mbed-os/pull/4109
3982: Ticker - kl25z bugfix for handling events in the past https://github.com/ARMmbed/mbed-os/pull/3982
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 128:9bcdf88f62b0 | 1 | /* mbed Microcontroller Library |
<> | 128:9bcdf88f62b0 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 128:9bcdf88f62b0 | 3 | * |
<> | 128:9bcdf88f62b0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 128:9bcdf88f62b0 | 5 | * you may not use this file except in compliance with the License. |
<> | 128:9bcdf88f62b0 | 6 | * You may obtain a copy of the License at |
<> | 128:9bcdf88f62b0 | 7 | * |
<> | 128:9bcdf88f62b0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 128:9bcdf88f62b0 | 9 | * |
<> | 128:9bcdf88f62b0 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 128:9bcdf88f62b0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 128:9bcdf88f62b0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 128:9bcdf88f62b0 | 13 | * See the License for the specific language governing permissions and |
<> | 128:9bcdf88f62b0 | 14 | * limitations under the License. |
<> | 128:9bcdf88f62b0 | 15 | */ |
<> | 128:9bcdf88f62b0 | 16 | #ifndef MBED_FILELIKE_H |
<> | 128:9bcdf88f62b0 | 17 | #define MBED_FILELIKE_H |
<> | 128:9bcdf88f62b0 | 18 | |
<> | 138:093f2bd7b9eb | 19 | #include "platform/mbed_toolchain.h" |
<> | 128:9bcdf88f62b0 | 20 | #include "drivers/FileBase.h" |
<> | 128:9bcdf88f62b0 | 21 | |
<> | 128:9bcdf88f62b0 | 22 | namespace mbed { |
<> | 128:9bcdf88f62b0 | 23 | /** \addtogroup drivers */ |
<> | 128:9bcdf88f62b0 | 24 | /** @{*/ |
<> | 128:9bcdf88f62b0 | 25 | |
<> | 138:093f2bd7b9eb | 26 | |
<> | 128:9bcdf88f62b0 | 27 | /* Class FileLike |
<> | 128:9bcdf88f62b0 | 28 | * A file-like object is one that can be opened with fopen by |
<> | 138:093f2bd7b9eb | 29 | * fopen("/name", mode). |
<> | 128:9bcdf88f62b0 | 30 | * |
<> | 128:9bcdf88f62b0 | 31 | * @Note Synchronization level: Set by subclass |
<> | 128:9bcdf88f62b0 | 32 | */ |
<> | 138:093f2bd7b9eb | 33 | class FileLike : public FileBase { |
<> | 138:093f2bd7b9eb | 34 | public: |
<> | 138:093f2bd7b9eb | 35 | /** Constructor FileLike |
<> | 138:093f2bd7b9eb | 36 | * |
<> | 138:093f2bd7b9eb | 37 | * @param name The name to use to open the file. |
<> | 138:093f2bd7b9eb | 38 | */ |
<> | 138:093f2bd7b9eb | 39 | FileLike(const char *name = NULL) : FileBase(name, FilePathType) {} |
<> | 138:093f2bd7b9eb | 40 | virtual ~FileLike() {} |
<> | 138:093f2bd7b9eb | 41 | |
<> | 138:093f2bd7b9eb | 42 | /** Read the contents of a file into a buffer |
<> | 138:093f2bd7b9eb | 43 | * |
<> | 138:093f2bd7b9eb | 44 | * @param buffer The buffer to read in to |
<> | 138:093f2bd7b9eb | 45 | * @param size The number of bytes to read |
<> | 138:093f2bd7b9eb | 46 | * @return The number of bytes read, 0 at end of file, negative error on failure |
<> | 138:093f2bd7b9eb | 47 | */ |
<> | 138:093f2bd7b9eb | 48 | virtual ssize_t read(void *buffer, size_t len) = 0; |
<> | 138:093f2bd7b9eb | 49 | |
<> | 138:093f2bd7b9eb | 50 | /** Write the contents of a buffer to a file |
<> | 138:093f2bd7b9eb | 51 | * |
<> | 138:093f2bd7b9eb | 52 | * @param buffer The buffer to write from |
<> | 138:093f2bd7b9eb | 53 | * @param size The number of bytes to write |
<> | 138:093f2bd7b9eb | 54 | * @return The number of bytes written, negative error on failure |
<> | 138:093f2bd7b9eb | 55 | */ |
<> | 138:093f2bd7b9eb | 56 | virtual ssize_t write(const void *buffer, size_t len) = 0; |
<> | 128:9bcdf88f62b0 | 57 | |
<> | 138:093f2bd7b9eb | 58 | /** Close a file |
<> | 138:093f2bd7b9eb | 59 | * |
<> | 138:093f2bd7b9eb | 60 | * @return 0 on success, negative error code on failure |
<> | 138:093f2bd7b9eb | 61 | */ |
<> | 138:093f2bd7b9eb | 62 | virtual int close() = 0; |
<> | 138:093f2bd7b9eb | 63 | |
<> | 138:093f2bd7b9eb | 64 | /** Flush any buffers associated with the file |
<> | 138:093f2bd7b9eb | 65 | * |
<> | 138:093f2bd7b9eb | 66 | * @return 0 on success, negative error code on failure |
<> | 138:093f2bd7b9eb | 67 | */ |
<> | 138:093f2bd7b9eb | 68 | virtual int sync() = 0; |
<> | 138:093f2bd7b9eb | 69 | |
<> | 138:093f2bd7b9eb | 70 | /** Check if the file in an interactive terminal device |
<> | 138:093f2bd7b9eb | 71 | * |
<> | 138:093f2bd7b9eb | 72 | * @return True if the file is a terminal |
<> | 138:093f2bd7b9eb | 73 | */ |
<> | 138:093f2bd7b9eb | 74 | virtual int isatty() = 0; |
<> | 138:093f2bd7b9eb | 75 | |
<> | 138:093f2bd7b9eb | 76 | /** Move the file position to a given offset from from a given location |
<> | 138:093f2bd7b9eb | 77 | * |
<> | 138:093f2bd7b9eb | 78 | * @param offset The offset from whence to move to |
<> | 138:093f2bd7b9eb | 79 | * @param whence The start of where to seek |
<> | 138:093f2bd7b9eb | 80 | * SEEK_SET to start from beginning of file, |
<> | 138:093f2bd7b9eb | 81 | * SEEK_CUR to start from current position in file, |
<> | 138:093f2bd7b9eb | 82 | * SEEK_END to start from end of file |
<> | 138:093f2bd7b9eb | 83 | * @return The new offset of the file |
<> | 138:093f2bd7b9eb | 84 | */ |
<> | 138:093f2bd7b9eb | 85 | virtual off_t seek(off_t offset, int whence = SEEK_SET) = 0; |
<> | 138:093f2bd7b9eb | 86 | |
<> | 138:093f2bd7b9eb | 87 | /** Get the file position of the file |
<> | 128:9bcdf88f62b0 | 88 | * |
<> | 138:093f2bd7b9eb | 89 | * @return The current offset in the file |
<> | 138:093f2bd7b9eb | 90 | */ |
<> | 138:093f2bd7b9eb | 91 | virtual off_t tell() = 0; |
<> | 138:093f2bd7b9eb | 92 | |
<> | 138:093f2bd7b9eb | 93 | /** Rewind the file position to the beginning of the file |
<> | 138:093f2bd7b9eb | 94 | * |
<> | 138:093f2bd7b9eb | 95 | * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET) |
<> | 138:093f2bd7b9eb | 96 | */ |
<> | 138:093f2bd7b9eb | 97 | virtual void rewind() = 0; |
<> | 138:093f2bd7b9eb | 98 | |
<> | 138:093f2bd7b9eb | 99 | /** Get the size of the file |
<> | 138:093f2bd7b9eb | 100 | * |
<> | 138:093f2bd7b9eb | 101 | * @return Size of the file in bytes |
<> | 138:093f2bd7b9eb | 102 | */ |
<> | 138:093f2bd7b9eb | 103 | virtual size_t size() = 0; |
<> | 138:093f2bd7b9eb | 104 | |
<> | 138:093f2bd7b9eb | 105 | /** Move the file position to a given offset from a given location. |
<> | 138:093f2bd7b9eb | 106 | * |
<> | 138:093f2bd7b9eb | 107 | * @param offset The offset from whence to move to |
<> | 138:093f2bd7b9eb | 108 | * @param whence SEEK_SET for the start of the file, SEEK_CUR for the |
<> | 138:093f2bd7b9eb | 109 | * current file position, or SEEK_END for the end of the file. |
<> | 138:093f2bd7b9eb | 110 | * |
<> | 138:093f2bd7b9eb | 111 | * @returns |
<> | 138:093f2bd7b9eb | 112 | * new file position on success, |
<> | 138:093f2bd7b9eb | 113 | * -1 on failure or unsupported |
<> | 128:9bcdf88f62b0 | 114 | */ |
<> | 138:093f2bd7b9eb | 115 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::seek") |
<> | 138:093f2bd7b9eb | 116 | virtual off_t lseek(off_t offset, int whence) { return seek(offset, whence); } |
<> | 138:093f2bd7b9eb | 117 | |
<> | 138:093f2bd7b9eb | 118 | /** Flush any buffers associated with the FileHandle, ensuring it |
<> | 138:093f2bd7b9eb | 119 | * is up to date on disk |
<> | 138:093f2bd7b9eb | 120 | * |
<> | 138:093f2bd7b9eb | 121 | * @returns |
<> | 138:093f2bd7b9eb | 122 | * 0 on success or un-needed, |
<> | 138:093f2bd7b9eb | 123 | * -1 on error |
<> | 138:093f2bd7b9eb | 124 | */ |
<> | 138:093f2bd7b9eb | 125 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::sync") |
<> | 138:093f2bd7b9eb | 126 | virtual int fsync() { return sync(); } |
<> | 128:9bcdf88f62b0 | 127 | |
<> | 138:093f2bd7b9eb | 128 | /** Find the length of the file |
<> | 138:093f2bd7b9eb | 129 | * |
<> | 138:093f2bd7b9eb | 130 | * @returns |
<> | 138:093f2bd7b9eb | 131 | * Length of the file |
<> | 138:093f2bd7b9eb | 132 | */ |
<> | 138:093f2bd7b9eb | 133 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::size") |
<> | 138:093f2bd7b9eb | 134 | virtual off_t flen() { return size(); } |
<> | 128:9bcdf88f62b0 | 135 | |
<> | 138:093f2bd7b9eb | 136 | protected: |
<> | 138:093f2bd7b9eb | 137 | /** Acquire exclusive access to this object. |
<> | 138:093f2bd7b9eb | 138 | */ |
<> | 138:093f2bd7b9eb | 139 | virtual void lock() { |
<> | 138:093f2bd7b9eb | 140 | // Stub |
<> | 138:093f2bd7b9eb | 141 | } |
<> | 138:093f2bd7b9eb | 142 | |
<> | 138:093f2bd7b9eb | 143 | /** Release exclusive access to this object. |
<> | 138:093f2bd7b9eb | 144 | */ |
<> | 138:093f2bd7b9eb | 145 | virtual void unlock() { |
<> | 138:093f2bd7b9eb | 146 | // Stub |
<> | 138:093f2bd7b9eb | 147 | } |
<> | 128:9bcdf88f62b0 | 148 | }; |
<> | 128:9bcdf88f62b0 | 149 | |
<> | 138:093f2bd7b9eb | 150 | |
<> | 138:093f2bd7b9eb | 151 | /** @}*/ |
<> | 128:9bcdf88f62b0 | 152 | } // namespace mbed |
<> | 128:9bcdf88f62b0 | 153 | |
<> | 128:9bcdf88f62b0 | 154 | #endif |