Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
File Class Reference
[Filesystem]
#include <File.h>
Inherits mbed::FileHandle.
Public Member Functions | |
File () | |
Create an uninitialized file. | |
File (FileSystem *fs, const char *path, int flags=O_RDONLY) | |
Create a file on a filesystem. | |
virtual | ~File () |
Destroy a file. | |
virtual int | open (FileSystem *fs, const char *path, int flags=O_RDONLY) |
Open a file on the filesystem. | |
virtual int | close () |
Close a file. | |
virtual ssize_t | read (void *buffer, size_t size) |
Read the contents of a file into a buffer. | |
virtual ssize_t | write (const void *buffer, size_t size) |
Write the contents of a buffer to a file. | |
virtual int | sync () |
Flush any buffers associated with the file. | |
virtual int | isatty () |
Check if the file in an interactive terminal device. | |
virtual off_t | seek (off_t offset, int whence=SEEK_SET) |
Move the file position to a given offset from from a given location. | |
virtual off_t | tell () |
Get the file position of the file. | |
virtual void | rewind () |
Rewind the file position to the beginning of the file. | |
virtual off_t | size () |
Get the size of the file. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::seek") virtual off_t lseek(off_t offset | |
Move the file position to a given offset from a given location. |
Detailed Description
File class.
Definition at line 30 of file File.h.
Constructor & Destructor Documentation
File | ( | ) |
Create an uninitialized file.
Must call open to initialize the file on a file system
File | ( | FileSystem * | fs, |
const char * | path, | ||
int | flags = O_RDONLY |
||
) |
Create a file on a filesystem.
Creates and opens a file on a filesystem
- Parameters:
-
fs Filesystem as target for the file path The name of the file to open flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
virtual ~File | ( | ) | [virtual] |
Destroy a file.
Closes file if the file is still open
Member Function Documentation
virtual int close | ( | ) | [virtual] |
virtual int isatty | ( | ) | [virtual] |
Check if the file in an interactive terminal device.
- Returns:
- True if the file is a terminal
Reimplemented from FileHandle.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::seek" | |||
) | [inherited] |
Move the file position to a given offset from a given location.
- Parameters:
-
offset The offset from whence to move to whence SEEK_SET for the start of the file, SEEK_CUR for the current file position, or SEEK_END for the end of the file.
- Returns:
- new file position on success, -1 on failure or unsupported
virtual int open | ( | FileSystem * | fs, |
const char * | path, | ||
int | flags = O_RDONLY |
||
) | [virtual] |
Open a file on the filesystem.
- Parameters:
-
fs Filesystem as target for the file path The name of the file to open flags The flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
- Returns:
- 0 on success, negative error code on failure
virtual ssize_t read | ( | void * | buffer, |
size_t | size | ||
) | [virtual] |
Read the contents of a file into a buffer.
- Parameters:
-
buffer The buffer to read in to size The number of bytes to read
- Returns:
- The number of bytes read, 0 at end of file, negative error on failure
Implements FileHandle.
virtual void rewind | ( | ) | [virtual] |
Rewind the file position to the beginning of the file.
- Note:
- This is equivalent to file_seek(file, 0, FS_SEEK_SET)
Reimplemented from FileHandle.
virtual off_t seek | ( | off_t | offset, |
int | whence = SEEK_SET |
||
) | [virtual] |
Move the file position to a given offset from from a given location.
- Parameters:
-
offset The offset from whence to move to whence The start of where to seek SEEK_SET to start from beginning of file, SEEK_CUR to start from current position in file, SEEK_END to start from end of file
- Returns:
- The new offset of the file
Implements FileHandle.
virtual off_t size | ( | ) | [virtual] |
virtual int sync | ( | ) | [virtual] |
Flush any buffers associated with the file.
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileHandle.
virtual off_t tell | ( | ) | [virtual] |
Get the file position of the file.
- Returns:
- The current offset in the file
Reimplemented from FileHandle.
virtual ssize_t write | ( | const void * | buffer, |
size_t | size | ||
) | [virtual] |
Write the contents of a buffer to a file.
- Parameters:
-
buffer The buffer to write from size The number of bytes to write
- Returns:
- The number of bytes written, negative error on failure
Implements FileHandle.
Generated on Tue Jul 12 2022 12:47:31 by
