File controller interface for reading/writing files.
More...
#include <stdint.h>
Go to the source code of this file.
|
struct FC * | FC_open (const char *fp, enum fc_mode_t mode) |
| Opens a file controller instance for the given file path and mode.
|
|
void | FC_close (struct FC *fc) |
| Closes the given file controller instance and frees its resources.
|
|
uint32_t | FC_read (struct FC *fc, uint32_t offset, uint32_t size, uint8_t *b) |
| Reads the given number of bytes from the file controller starting at the given offset.
|
|
uint32_t | FC_readto (struct FC *fc, uint32_t offset, uint32_t size, uint32_t maxCount, uint8_t *b) |
| Reads up to the given number of bytes from the file controller starting at the given offset, up to the given maximum count of bytes or until the end of the file is reached.
|
|
uint32_t | FC_write (struct FC *fc, uint32_t offset, uint32_t size, const uint8_t *b) |
| Writes the given number of bytes to the file controller starting at the given offset.
|
|
uint32_t | FC_filesize (struct FC *fc) |
| Returns the size of the file backing the given file controller. This performs a seek to the end of the file to determine its size and then seeks back to the beginning.
|
|
File controller interface for reading/writing files.
◆ fc_mode_t
File controller open mode.
Enumerator |
---|
FC_MODE_READ | Equivalent to "rb".
|
FC_MODE_WRITE | Equivalent to "wb".
|
◆ FC_close()
void FC_close |
( |
struct FC * | fc | ) |
|
Closes the given file controller instance and frees its resources.
- Parameters
-
fc | target file controller instance |
◆ FC_filesize()
uint32_t FC_filesize |
( |
struct FC * | fc | ) |
|
Returns the size of the file backing the given file controller. This performs a seek to the end of the file to determine its size and then seeks back to the beginning.
- Parameters
-
fc | target file controller instance |
- Returns
- the size of the file in bytes, or 0 if an error occurred
◆ FC_open()
struct FC * FC_open |
( |
const char * | fp, |
|
|
enum fc_mode_t | mode ) |
Opens a file controller instance for the given file path and mode.
- Parameters
-
fp | file path to open |
mode | file open mode |
- Returns
- a file controller instance, or NULL if an error occurred
◆ FC_read()
uint32_t FC_read |
( |
struct FC * | fc, |
|
|
uint32_t | offset, |
|
|
uint32_t | size, |
|
|
uint8_t * | b ) |
Reads the given number of bytes from the file controller starting at the given offset.
- Parameters
-
fc | target file controller instance |
offset | offset in bytes from the start of the file |
size | number of bytes to read |
b | buffer to read into |
- Returns
- the number of bytes read, otherwise 0 or a value less than
size
if an error occurred
◆ FC_readto()
uint32_t FC_readto |
( |
struct FC * | fc, |
|
|
uint32_t | offset, |
|
|
uint32_t | size, |
|
|
uint32_t | maxCount, |
|
|
uint8_t * | b ) |
Reads up to the given number of bytes from the file controller starting at the given offset, up to the given maximum count of bytes or until the end of the file is reached.
- Parameters
-
fc | target file controller instance |
offset | offset in bytes from the start of the file |
size | number of bytes to read |
maxCount | maximum number of bytes to read |
b | buffer to read into |
- Returns
- the number of bytes read, otherwise 0 or a value less than
size
if an error occurred
◆ FC_write()
uint32_t FC_write |
( |
struct FC * | fc, |
|
|
uint32_t | offset, |
|
|
uint32_t | size, |
|
|
const uint8_t * | b ) |
Writes the given number of bytes to the file controller starting at the given offset.
- Parameters
-
fc | target file controller instance |
offset | offset in bytes from the start of the file |
size | number of bytes to write |
b | buffer to write |
- Returns
- the number of bytes written, otherwise 0 or a value less than
size
if an error occurred