Rtos API example

Embed: (wiki syntax)

« Back to documentation index

FileLike Class Reference

Class FileLike. More...

#include <FileLike.h>

Inherits mbed::FileHandle, mbed::FileBase, and NonCopyable< FileLike >.

Inherited by Stream.

Public Member Functions

 FileLike (const char *name=NULL)
 Constructor FileLike.
virtual ssize_t read (void *buffer, size_t size)=0
 Read the contents of a file into a buffer.
virtual ssize_t write (const void *buffer, size_t size)=0
 Write the contents of a buffer to a file.
virtual off_t seek (off_t offset, int whence=SEEK_SET)=0
 Move the file position to a given offset from from a given location.
virtual int close ()=0
 Close 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 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.

Protected Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Private Member Functions

 MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &)
 NonCopyable copy constructor.
 MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator
 NonCopyable copy assignment operator.

Detailed Description

Class FileLike.

A file-like object is one that can be opened with fopen by fopen("/name", mode).

Note:
Synchronization level: Set by subclass

Definition at line 38 of file FileLike.h.


Constructor & Destructor Documentation

FileLike ( const char *  name = NULL )

Constructor FileLike.

Parameters:
nameThe name to use to open the file.

Definition at line 44 of file FileLike.h.


Member Function Documentation

virtual int close (  ) [pure virtual, inherited]

Close a file.

Returns:
0 on success, negative error code on failure

Implemented in UARTSerial, File, and Stream.

virtual int isatty (  ) [virtual, inherited]

Check if the file in an interactive terminal device.

Returns:
True if the file is a terminal
False if the file is not a terminal
Negative error code on failure

Reimplemented in UARTSerial, File, and Stream.

Definition at line 103 of file FileHandle.h.

MBED_DEPRECATED ( "Invalid copy assignment of a NonCopyable< FileBase > resource."   ) [protected, inherited]

NonCopyable copy assignment operator.

A compile time warning is issued when this function is used and a runtime warning is printed when the copy construction of the non copyable happens.

If you see this warning, your code is probably doing something unspecified. Copy of non copyable resources can lead to resource leak and random error.

MBED_DEPRECATED ( "Invalid copy construction of a NonCopyable< FileBase > resource."   ) const [protected, inherited]

NonCopyable copy constructor.

A compile time warning is issued when this function is used and a runtime warning is printed when the copy construction of the non copyable happens.

If you see this warning, your code is probably doing something unspecified. Copy of non copyable resources can lead to resource leak and random error.

Definition at line 171 of file NonCopyable.h.

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:
offsetThe offset from whence to move to
whenceSEEK_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 ssize_t read ( void *  buffer,
size_t  size 
) [pure virtual, inherited]

Read the contents of a file into a buffer.

Devices acting as FileHandles should follow POSIX semantics:

* if no data is available, and non-blocking set return -EAGAIN * if no data is available, and blocking set, wait until data is available * If any data is available, call returns immediately

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

Implemented in UARTSerial, File, and Stream.

virtual void rewind (  ) [virtual, inherited]

Rewind the file position to the beginning of the file.

Note:
This is equivalent to seek(0, SEEK_SET)

Reimplemented in File, and Stream.

Definition at line 123 of file FileHandle.h.

virtual off_t seek ( off_t  offset,
int  whence = SEEK_SET 
) [pure virtual, inherited]

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, negative error code on failure

Implemented in UARTSerial, File, and Stream.

off_t size (  ) [virtual, inherited]

Get the size of the file.

Returns:
Size of the file in bytes

Reimplemented in File, and Stream.

Definition at line 22 of file FileHandle.cpp.

virtual int sync (  ) [virtual, inherited]

Flush any buffers associated with the file.

Returns:
0 on success, negative error code on failure

Reimplemented in UARTSerial, File, and Stream.

Definition at line 92 of file FileHandle.h.

virtual off_t tell (  ) [virtual, inherited]

Get the file position of the file.

Note:
This is equivalent to seek(0, SEEK_CUR)
Returns:
The current offset in the file, negative error code on failure

Reimplemented in File, and Stream.

Definition at line 114 of file FileHandle.h.

virtual ssize_t write ( const void *  buffer,
size_t  size 
) [pure virtual, inherited]

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

Implemented in UARTSerial, File, and Stream.