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)
 

Detailed Description

Function Documentation

◆ M_fs_file_open()

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.

Parameters
[out]fdThe file object created upon success. Will be set to NULL if there was an error.
[in]pathThe path to open.
[in]buf_sizeSet a buffer size to enable buffered read and write. Use 0 to disable buffering.
[in]modeM_fs_file_mode_t open mode.
[in]permsAdditional 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.
Returns
Result.

◆ M_fs_file_open_iostream()

M_fs_error_t M_fs_file_open_iostream ( M_fs_file_t **  fd,
M_fs_iostream_t  stream 
)

Open a standard IO stream.

Parameters
[out]fdThe file object created upon success. Will be set to NULL if there was an error.
[in]streamThe stream to open.
Returns
Result.

◆ M_fs_file_close()

void M_fs_file_close ( M_fs_file_t fd)

Close an open file.

Parameters
[in]fdThe file object.

◆ M_fs_file_read()

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.

Parameters
[in]fdThe file object.
[out]bufA buffer to put the read data into.
[in]buf_lenThe size of the buffer.
[out]read_lenHow much data was read into buf.
[in]flagsM_fs_file_read_write_t flags to control the read.
Returns
Result.

◆ M_fs_file_write()

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.

Parameters
[in]fdThe file object.
[in]bufThe data to write.
[in]countThe length of the data to write.
[out]wrote_lenThe amount of data written to the file.
[in]flagsM_fs_file_read_write_t flags to control the write.
Returns
Result.

◆ M_fs_file_seek()

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.

Parameters
[in]fdThe file object.
[in]offsetHow much to move the offset relative to from. Can be negative to move backwards.
[in]fromWhere the offset is relative to.
Returns
Result.

◆ M_fs_file_sync()

M_fs_error_t M_fs_file_sync ( M_fs_file_t fd,
M_uint32  type 
)

Flush file buffer to disk.

Parameters
[in]fdThe file object.
[in]typeM_fs_file_sync_t type of sync to perform.
Returns
Result.

◆ M_fs_file_read_bytes()

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.

Parameters
[in]pathThe path to read from.
[in]max_readA maximum of bytes to read. 0 for no maximum.
[out]bufA buffer that will be allocated and contain the file contents. It will be NULL terminated on success.
[out]bytes_readThe number of bytes read and contained in the buffer excluding the NULL terminator.
Returns
Result.

◆ M_fs_file_write_bytes()

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.

Parameters
[in]pathThe path of the file to write into.
[in]bufBuffer containing the data to write into the file.
[in]write_lenThe 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]modeM_fs_file_mode_t mode. Only supports APPEND. Used to control appending vs overwriting. The default is to overwrite the file.
[out]bytes_writtenThe number of bytes from buf written to the file. Optional, pass NULL if not needed.
Returns
Result.