Mstdlib-1.24.0
|
Functions | |
M_fs_error_t | M_fs_file_open (M_fs_file_t **fd, const char *path, size_t buf_size, M_uint32 mode, const M_fs_perms_t *perms) |
M_fs_error_t | M_fs_file_open_iostream (M_fs_file_t **fd, M_fs_iostream_t stream) |
void | M_fs_file_close (M_fs_file_t *fd) |
M_fs_error_t | M_fs_file_read (M_fs_file_t *fd, unsigned char *buf, size_t buf_len, size_t *read_len, M_uint32 flags) |
M_fs_error_t | M_fs_file_write (M_fs_file_t *fd, const unsigned char *buf, size_t count, size_t *wrote_len, M_uint32 flags) |
M_fs_error_t | M_fs_file_seek (M_fs_file_t *fd, M_int64 offset, M_fs_file_seek_t from) |
M_fs_error_t | M_fs_file_sync (M_fs_file_t *fd, M_uint32 type) |
M_fs_error_t | M_fs_file_read_bytes (const char *path, size_t max_read, unsigned char **buf, size_t *bytes_read) |
M_fs_error_t | M_fs_file_write_bytes (const char *path, const unsigned char *buf, size_t write_len, M_uint32 mode, size_t *bytes_written) |
M_fs_error_t M_fs_file_open | ( | M_fs_file_t ** | fd, |
const char * | path, | ||
size_t | buf_size, | ||
M_uint32 | mode, | ||
const M_fs_perms_t * | perms | ||
) |
Open a file.
The set of flags you pass to mode must include M_FS_FILE_MODE_READ and/or M_FS_FILE_MODE_WRITE. System umask is honored when creating a file.
The other M_fs_file_mode_t flags can be used as well, they just need to be OR'd with M_FS_FILE_MODE_READ and/or M_FS_FILE_MODE_WRITE.
[out] | fd | The file object created upon success. Will be set to NULL if there was an error. |
[in] | path | The path to open. |
[in] | buf_size | Set a buffer size to enable buffered read and write. Use 0 to disable buffering. |
[in] | mode | M_fs_file_mode_t open mode. |
[in] | perms | Additional perms to apply to the file if it does not exist and is created. Umake is honored when perms are set. E.g. perms & ~umask is used. If perms is NULL a default of rw-rw-r– & ~umask is used. |
M_fs_error_t M_fs_file_open_iostream | ( | M_fs_file_t ** | fd, |
M_fs_iostream_t | stream | ||
) |
Open a standard IO stream.
[out] | fd | The file object created upon success. Will be set to NULL if there was an error. |
[in] | stream | The stream to open. |
void M_fs_file_close | ( | M_fs_file_t * | fd | ) |
Close an open file.
[in] | fd | The file object. |
M_fs_error_t M_fs_file_read | ( | M_fs_file_t * | fd, |
unsigned char * | buf, | ||
size_t | buf_len, | ||
size_t * | read_len, | ||
M_uint32 | flags | ||
) |
Read from a file.
[in] | fd | The file object. |
[out] | buf | A buffer to put the read data into. |
[in] | buf_len | The size of the buffer. |
[out] | read_len | How much data was read into buf. |
[in] | flags | M_fs_file_read_write_t flags to control the read. |
M_fs_error_t M_fs_file_write | ( | M_fs_file_t * | fd, |
const unsigned char * | buf, | ||
size_t | count, | ||
size_t * | wrote_len, | ||
M_uint32 | flags | ||
) |
Write data to a file.
[in] | fd | The file object. |
[in] | buf | The data to write. |
[in] | count | The length of the data to write. |
[out] | wrote_len | The amount of data written to the file. |
[in] | flags | M_fs_file_read_write_t flags to control the write. |
M_fs_error_t M_fs_file_seek | ( | M_fs_file_t * | fd, |
M_int64 | offset, | ||
M_fs_file_seek_t | from | ||
) |
Move/Set the read/write offset within an file.
[in] | fd | The file object. |
[in] | offset | How much to move the offset relative to from. Can be negative to move backwards. |
[in] | from | Where the offset is relative to. |
M_fs_error_t M_fs_file_sync | ( | M_fs_file_t * | fd, |
M_uint32 | type | ||
) |
Flush file buffer to disk.
[in] | fd | The file object. |
[in] | type | M_fs_file_sync_t type of sync to perform. |
M_fs_error_t M_fs_file_read_bytes | ( | const char * | path, |
size_t | max_read, | ||
unsigned char ** | buf, | ||
size_t * | bytes_read | ||
) |
Read a file into a buffer as a str.
[in] | path | The path to read from. |
[in] | max_read | A maximum of bytes to read. 0 for no maximum. |
[out] | buf | A buffer that will be allocated and contain the file contents. It will be NULL terminated on success. |
[out] | bytes_read | The number of bytes read and contained in the buffer excluding the NULL terminator. |
M_fs_error_t M_fs_file_write_bytes | ( | const char * | path, |
const unsigned char * | buf, | ||
size_t | write_len, | ||
M_uint32 | mode, | ||
size_t * | bytes_written | ||
) |
Write a str to a file.
[in] | path | The path of the file to write into. |
[in] | buf | Buffer containing the data to write into the file. |
[in] | write_len | The number of bytes from buf to write. Optional, pass 0 to use M_str_len to determine length of a NULL terminated buffer to write. |
[in] | mode | M_fs_file_mode_t mode. Only supports APPEND. Used to control appending vs overwriting. The default is to overwrite the file. |
[out] | bytes_written | The number of bytes from buf written to the file. Optional, pass NULL if not needed. |