88 const char* restrict filename,
89 const char* restrict mode,
183 size_t total_bytes_written = 0;
184 while (total_bytes_written < size) {
187 (
char*)buf + total_bytes_written,
188 size - total_bytes_written,
191 if (bytes_written == 0) {
break; }
192 total_bytes_written += bytes_written;
195 return total_bytes_written;
208 size_t total_bytes_read = 0;
209 while (total_bytes_read < size) {
212 (
char*)buf + total_bytes_read,
213 size - total_bytes_read,
216 if (bytes_read == 0) {
break; }
217 total_bytes_read += bytes_read;
220 return total_bytes_read;
uintptr_t bio_funwrap(bio_file_t file)
Retrieve an OS handle from a bio_file_t.
bio_file_t BIO_STDIN
Standard input.
size_t bio_fread(bio_file_t file, void *buf, size_t size, bio_error_t *error)
Read from a file.
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.
Definition file.h:207
bool bio_fclose(bio_file_t file, bio_error_t *error)
Close a file handle.
size_t bio_fwrite(bio_file_t file, const void *buf, size_t size, bio_error_t *error)
Write to a file.
int64_t bio_ftell(bio_file_t file, bio_error_t *error)
Retrieve the file offset.
bio_file_t BIO_STDERR
Standard error.
bool bio_fflush(bio_file_t file, bio_error_t *error)
Flush the file buffer.
bool bio_fstat(bio_file_t file, bio_stat_t *stat, bio_error_t *error)
Retrieves statistics about a file.
bool bio_fseek(bio_file_t file, int64_t offset, int origin, bio_error_t *error)
Modify the file offset.
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.
Definition file.h:182
bio_file_t BIO_STDOUT
Standard output.
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.
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.
An error returned from a function.
Definition bio.h:468
Handle to a file.
Definition file.h:15
Statistics about a file.
Definition file.h:27
uint64_t size
The file size in bytes.
Definition file.h:28