Retarget interface provides routines that can be called by the standard C library retarget interface.
More...
|
int32_t | fs_fopen (const char *path, int32_t mode) |
| Open a file.
|
|
int32_t | fs_fclose (int32_t handle) |
| Close a file.
|
|
int32_t | fs_fwrite (int32_t handle, const void *buf, uint32_t cnt) |
| Write to a file.
|
|
int32_t | fs_fread (int32_t handle, void *buf, uint32_t cnt) |
| Read from a file.
|
|
int32_t | fs_fflush (int32_t handle) |
| Flush file buffers.
|
|
int64_t | fs_fseek (int32_t handle, int64_t offset, int32_t whence) |
| Move the file position pointer.
|
|
int64_t | fs_fsize (int32_t handle) |
| Get file size.
|
|
Retarget interface provides routines that can be called by the standard C library retarget interface.
◆ fs_fclose()
int32_t fs_fclose |
( |
int32_t | handle | ) |
|
|
extern |
Close a file.
- Parameters
-
[in] | handle | File handle of an opened file. |
- Returns
- zero if the file was successfully closed, or negative fsStatus return code on failure
The function fs_fclose closes the file associated with the file descriptor 'handle'.
◆ fs_fflush()
int32_t fs_fflush |
( |
int32_t | handle | ) |
|
|
extern |
Flush file buffers.
- Parameters
-
[in] | handle | File handle of an opened file. |
- Returns
- zero on success, or negative fsStatus return code on failure
The function fs_fflush flushes internal buffers to the storage media and ensures consistent file system state.
◆ fs_fopen()
int32_t fs_fopen |
( |
const char * | path, |
|
|
int32_t | mode ) |
|
extern |
Open a file.
- Parameters
-
[in] | path | String specifying the pathname of the file to be opened. |
[in] | mode | Integer bitmap specifying the file open mode. |
- Returns
- a non-negative integer representing the file handle on success, or negative fsStatus return code on failure
The function fs_fopen opens a file specified by the pathname.
The mode parameter is a bitmap that specifies the file open mode. The following bits are exclusive:
- FS_FOPEN_RD: open file for reading only
- FS_FOPEN_WR: open file for writing only
- FS_FOPEN_RDWR: open file for reading and writing
In addition, any combination of the values below can be set:
- FS_FOPEN_APPEND: if set, the file offset is set to the end of file prior to each write
- FS_FOPEN_CREATE: if set, the file is created if it does not exist
- FS_FOPEN_TRUNCATE: if set, the size of an existing file opened for writing is truncated to zero
The file position offset shall be set to the beginning of the file unless append mode is specified.
◆ fs_fread()
int32_t fs_fread |
( |
int32_t | handle, |
|
|
void * | buf, |
|
|
uint32_t | cnt ) |
|
extern |
Read from a file.
- Parameters
-
[in] | handle | File handle of an opened file. |
[out] | buf | Pointer to the buffer to store read data. |
[in] | cnt | Number of bytes to read. |
- Returns
- number of bytes actually read, 0 at the EOF, or negative fsStatus return code on failure
The function fs_fread reads cnt bytes from the file associated with the file descriptor 'handle', into the buffer pointed to by buf. The actual number of bytes read can be less than cnt.
◆ fs_fseek()
int64_t fs_fseek |
( |
int32_t | handle, |
|
|
int64_t | offset, |
|
|
int32_t | whence ) |
|
extern |
Move the file position pointer.
- Parameters
-
[in] | handle | File handle of an opened file. |
[in] | offset | The number of bytes to move. |
[in] | whence | File position location. |
- Returns
- current file position from the beginning of the file, or negative fsStatus return code on failure
The function fs_fseek moves the file position pointer as specified with parameters 'offset' and 'whence'. Parameter 'whence' can have the following possible values:
- FS_FSEEK_SET: set the file position pointer to offset bytes from the start of the file
- FS_FSEEK_CUR: set the file position pointer to offset bytes from the current location
- FS_FSEEK_END: set the file position pointer to offset bytes from the end of the file
◆ fs_fsize()
int64_t fs_fsize |
( |
int32_t | handle | ) |
|
|
extern |
Get file size.
- Parameters
-
[in] | handle | File handle of an opened file. |
- Returns
- file size in bytes, or negative fsStatus return code on failure
The function fs_fsize retrieves the size of an opened file associated with the file descriptor 'handle'.
◆ fs_fwrite()
int32_t fs_fwrite |
( |
int32_t | handle, |
|
|
const void * | buf, |
|
|
uint32_t | cnt ) |
|
extern |
Write to a file.
- Parameters
-
[in] | handle | File handle of an opened file. |
[in] | buf | Pointer to the buffer containing data to write. |
[in] | cnt | Number of bytes to write. |
- Returns
- number of bytes actually written, or negative fsStatus return code on failure
The function fs_fwrite shall write cnt bytes from the buffer pointed to by buf to the file associated with the open file descriptor 'handle'.