RAII wrapper around an oveRTOS file handle.
More...
#include <fs.hpp>
|
|
| File () |
| | Constructs a File object with no open file (invalid state).
|
| |
|
| ~File () |
| | Destroys the file object, closing the file if it is still open.
|
| |
|
| File (const File &)=delete |
| |
|
File & | operator= (const File &)=delete |
| |
| | File (File &&other) noexcept |
| | Move constructor — transfers ownership of the file handle.
|
| |
| File & | operator= (File &&other) noexcept |
| | Move-assignment operator — closes the current file and takes ownership.
|
| |
| int | open (const char *path, int flags) |
| | Opens a file at the specified path.
|
| |
| int | close () |
| | Closes the file and invalidates the handle.
|
| |
| int | read (void *buf, size_t count, size_t *bytes_read) |
| | Reads bytes from the file at the current position.
|
| |
| int | write (const void *buf, size_t count, size_t *bytes_written) |
| | Writes bytes to the file at the current position.
|
| |
| int | seek (long offset, int whence) |
| | Repositions the file offset.
|
| |
| long | tell () |
| | Returns the current file offset.
|
| |
| int | size (size_t *out_size) |
| | Returns the size of the file.
|
| |
| bool | valid () const |
| | Returns true if the file handle is valid (file is open).
|
| |
| ove_file_t | handle () const |
| | Returns the raw oveRTOS file handle.
|
| |
RAII wrapper around an oveRTOS file handle.
The file is opened explicitly via open() and closed either by calling close() or automatically by the destructor. If the object is destroyed with an open file, the destructor calls close().
- Note
- Non-copyable; movable.
◆ File()
| ove::File::File |
( |
File && |
other | ) |
|
|
inlinenoexcept |
Move constructor — transfers ownership of the file handle.
- Parameters
-
| other | The source; its handle is set to null after the move. |
◆ operator=()
| File & ove::File::operator= |
( |
File && |
other | ) |
|
|
inlinenoexcept |
Move-assignment operator — closes the current file and takes ownership.
- Parameters
-
| other | The source; its handle is set to null after the move. |
- Returns
- Reference to this object.
◆ open()
| int ove::File::open |
( |
const char * |
path, |
|
|
int |
flags |
|
) |
| |
|
inline |
Opens a file at the specified path.
- Parameters
-
| [in] | path | Absolute path to the file. |
| [in] | flags | Open flags (e.g., read-only, write, create). |
- Returns
OVE_OK on success, or a negative error code.
◆ close()
Closes the file and invalidates the handle.
Safe to call on an already-closed file (returns OVE_OK).
- Returns
OVE_OK on success, or a negative error code.
◆ read()
| int ove::File::read |
( |
void * |
buf, |
|
|
size_t |
count, |
|
|
size_t * |
bytes_read |
|
) |
| |
|
inline |
Reads bytes from the file at the current position.
- Parameters
-
| [out] | buf | Buffer to receive the read data. |
| [in] | count | Maximum number of bytes to read. |
| [out] | bytes_read | Receives the actual number of bytes read. |
- Returns
OVE_OK on success, or a negative error code.
◆ write()
| int ove::File::write |
( |
const void * |
buf, |
|
|
size_t |
count, |
|
|
size_t * |
bytes_written |
|
) |
| |
|
inline |
Writes bytes to the file at the current position.
- Parameters
-
| [in] | buf | Pointer to the data to write. |
| [in] | count | Number of bytes to write. |
| [out] | bytes_written | Receives the actual number of bytes written. |
- Returns
OVE_OK on success, or a negative error code.
◆ seek()
| int ove::File::seek |
( |
long |
offset, |
|
|
int |
whence |
|
) |
| |
|
inline |
Repositions the file offset.
- Parameters
-
| [in] | offset | Byte offset relative to whence. |
| [in] | whence | Seek origin (SEEK_SET, SEEK_CUR, or SEEK_END). |
- Returns
OVE_OK on success, or a negative error code.
◆ tell()
Returns the current file offset.
- Returns
- The current byte offset from the start of the file, or -1 on error.
◆ size()
| int ove::File::size |
( |
size_t * |
out_size | ) |
|
|
inline |
Returns the size of the file.
- Parameters
-
| [out] | out_size | Receives the file size in bytes. |
- Returns
OVE_OK on success, or a negative error code.
◆ valid()
| bool ove::File::valid |
( |
| ) |
const |
|
inline |
Returns true if the file handle is valid (file is open).
- Returns
true when a file has been successfully opened.
◆ handle()
| ove_file_t ove::File::handle |
( |
| ) |
const |
|
inline |
Returns the raw oveRTOS file handle.
- Returns
- The opaque
ove_file_t handle.
The documentation for this class was generated from the following file: