Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
mbed::File Class Reference

#include <File.h>

Inheritance diagram for mbed::File:
mbed::FileHandle mbed::NonCopyable< FileHandle >

Public Member Functions

 File ()
 
 File (FileSystem *fs, const char *path, int flags=O_RDONLY)
 
virtual ~File ()
 
virtual int open (FileSystem *fs, const char *path, int flags=O_RDONLY)
 
virtual int close ()
 
virtual ssize_t read (void *buffer, size_t size)
 
virtual ssize_t write (const void *buffer, size_t size)
 
virtual int sync ()
 
virtual int isatty ()
 
virtual off_t seek (off_t offset, int whence=SEEK_SET)
 
virtual off_t tell ()
 
virtual void rewind ()
 
virtual off_t size ()
 
- Public Member Functions inherited from mbed::FileHandle
virtual off_t lseek (off_t offset, int whence)
 
virtual int fsync ()
 
virtual off_t flen ()
 
virtual int set_blocking (bool blocking)
 
virtual bool is_blocking () const
 
virtual short poll (short events) const
 
bool writable () const
 
bool readable () const
 
virtual void sigio (Callback< void()> func)
 

Detailed Description

File class

Constructor & Destructor Documentation

mbed::File::File ( )

Create an uninitialized file

Must call open to initialize the file on a file system

mbed::File::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
fsFilesystem as target for the file
pathThe name of the file to open
flagsThe 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
mbed::File::~File ( )
virtual

Destroy a file

Closes file if the file is still open

Member Function Documentation

int mbed::File::close ( )
virtual

Close a file

Returns
0 on success, negative error code on failure

Implements mbed::FileHandle.

int mbed::File::isatty ( )
virtual

Check if the file in an interactive terminal device

Returns
True if the file is a terminal

Reimplemented from mbed::FileHandle.

int mbed::File::open ( FileSystem fs,
const char *  path,
int  flags = O_RDONLY 
)
virtual

Open a file on the filesystem

Parameters
fsFilesystem as target for the file
pathThe name of the file to open
flagsThe 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
ssize_t mbed::File::read ( void *  buffer,
size_t  size 
)
virtual

Read the contents of a file into a buffer

Parameters
bufferThe buffer to read in to
sizeThe number of bytes to read
Returns
The number of bytes read, 0 at end of file, negative error on failure

Implements mbed::FileHandle.

void mbed::File::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 mbed::FileHandle.

off_t mbed::File::seek ( off_t  offset,
int  whence = SEEK_SET 
)
virtual

Move the file position to a given offset from from a given location

Parameters
offsetThe offset from whence to move to
whenceThe 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 mbed::FileHandle.

off_t mbed::File::size ( )
virtual

Get the size of the file

Returns
Size of the file in bytes

Reimplemented from mbed::FileHandle.

int mbed::File::sync ( )
virtual

Flush any buffers associated with the file

Returns
0 on success, negative error code on failure

Reimplemented from mbed::FileHandle.

off_t mbed::File::tell ( )
virtual

Get the file position of the file

Returns
The current offset in the file

Reimplemented from mbed::FileHandle.

ssize_t mbed::File::write ( const void *  buffer,
size_t  size 
)
virtual

Write the contents of a buffer to a file

Parameters
bufferThe buffer to write from
sizeThe number of bytes to write
Returns
The number of bytes written, negative error on failure

Implements mbed::FileHandle.


The documentation for this class was generated from the following files:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.