Read/write to files. More...
Data Structures | |
struct | bio_file_t |
Handle to a file. More... | |
struct | bio_stat_t |
Statistics about a file. More... | |
Functions | |
bool | bio_fdopen (bio_file_t *file_ptr, uintptr_t fd, bio_error_t *error) |
Wraps a handle from the OS into a bio_file_t. | |
uintptr_t | bio_funwrap (bio_file_t file) |
Retrieve an OS handle from a bio_file_t. | |
bool | bio_fopen (bio_file_t *file_ptr, const char *restrict filename, const char *restrict mode, bio_error_t *error) |
Open a file for reading or writing. | |
size_t | bio_fwrite (bio_file_t file, const void *buf, size_t size, bio_error_t *error) |
Write to a file. | |
size_t | bio_fread (bio_file_t file, void *buf, size_t size, bio_error_t *error) |
Read from a file. | |
bool | bio_fseek (bio_file_t file, int64_t offset, int origin, bio_error_t *error) |
Modify the file offset. | |
int64_t | bio_ftell (bio_file_t file, bio_error_t *error) |
Retrieve the file offset. | |
bool | bio_fflush (bio_file_t file, bio_error_t *error) |
Flush the file buffer. | |
bool | bio_fclose (bio_file_t file, bio_error_t *error) |
Close a file handle. | |
bool | bio_fstat (bio_file_t file, bio_stat_t *stat, bio_error_t *error) |
Retrieves statistics about a file. | |
static size_t | bio_fwrite_exactly (bio_file_t file, const void *buf, size_t size, bio_error_t *error) |
Convenient function to write exactly a number of bytes to a file without short write. | |
static size_t | bio_fread_exactly (bio_file_t file, void *buf, size_t size, bio_error_t *error) |
Convenient function to read exactly a number of bytes from a file without short read. | |
Variables | |
bio_file_t | BIO_STDIN |
Standard input. | |
bio_file_t | BIO_STDOUT |
Standard output. | |
bio_file_t | BIO_STDERR |
Standard error. | |
Read/write to files.
bool bio_fclose | ( | bio_file_t | file, |
bio_error_t * | error | ||
) |
Close a file handle.
bool bio_fdopen | ( | bio_file_t * | file_ptr, |
uintptr_t | fd, | ||
bio_error_t * | error | ||
) |
Wraps a handle from the OS into a bio_file_t.
This can be used for platform-specific special files (e.g: memfd in Linux, mailslot in Windows).
file_ptr | Pointer to a file handle. This will only be set if the open was successful. |
fd | A platform-specific handle. For Unix platforms, it is a file descriptor. For Windows, it is a HANDLE . |
error | See Error handling. |
bool bio_fflush | ( | bio_file_t | file, |
bio_error_t * | error | ||
) |
Flush the file buffer.
This is similar to stdlib flush
.
bool bio_fopen | ( | bio_file_t * | file_ptr, |
const char *restrict | filename, | ||
const char *restrict | mode, | ||
bio_error_t * | error | ||
) |
Open a file for reading or writing.
This is similar to stdlib fopen_s
.
file_ptr | Pointer to a file handle. This will only be set if the open was successful. |
filename | The file to open. |
mode | Mode string |
error | See Error handling |
size_t bio_fread | ( | bio_file_t | file, |
void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
Read from a file.
This is similar to stdlib fread
.
|
inlinestatic |
Convenient function to read exactly a number of bytes from a file without short read.
error
. bool bio_fseek | ( | bio_file_t | file, |
int64_t | offset, | ||
int | origin, | ||
bio_error_t * | error | ||
) |
Modify the file offset.
This is similar to stdlib fseek
.
bool bio_fstat | ( | bio_file_t | file, |
bio_stat_t * | stat, | ||
bio_error_t * | error | ||
) |
Retrieves statistics about a file.
int64_t bio_ftell | ( | bio_file_t | file, |
bio_error_t * | error | ||
) |
Retrieve the file offset.
This is similar to stdlib ftell
.
uintptr_t bio_funwrap | ( | bio_file_t | file | ) |
Retrieve an OS handle from a bio_file_t.
This can be used to call platform-specific API such as ioctl
or flock
.
For Unix platforms, this is will return a file descriptor. A value of -1 is possible if the file was closed with bio_fclose.
For Windows, this will return a HANDLE
. A value of INVALID_HANDLE_VALUE
may be returned.
size_t bio_fwrite | ( | bio_file_t | file, |
const void * | buf, | ||
size_t | size, | ||
bio_error_t * | error | ||
) |
Write to a file.
This is similar to stdlib fwrite
.
|
inlinestatic |
Convenient function to write exactly a number of bytes to a file without short write.
error
.
|
extern |
Standard error.
|
extern |
Standard input.
|
extern |
Standard output.