|
htils 1
A small set of utilities for C programming.
|
Go to the source code of this file.
Functions | |
| u64 | file_size_stream (FILE *stream) |
| Gets the size of a file from a file stream. | |
| u64 | file_size (const string *path) |
Gets the size of a file at path. | |
| string * | read_file_from_stream (arena_t *arena, FILE *stream) |
Reads the contents of a file from stream into a string. | |
| string * | read_file (arena_t *arena, const string *path) |
Reads the contents of a file at path into a string. | |
| string * | read_file_from_stream_bytes (arena_t *arena, FILE *stream, const u64 bytes) |
Read bytes from file stream to string. | |
| string * | read_file_bytes (arena_t *arena, const string *path, const u64 bytes) |
Read bytes from a file path to string. | |
| u64 | write_to_file_stream (FILE *stream, const string *contents) |
Write contents to file stream. | |
| u64 | write_to_file (const string *path, const string *contents) |
Write contents to file path. | |
| u64 | write_to_file_stream_bytes (FILE *stream, const string *contents, const u64 bytes) |
Write bytes from contents to stream. | |
| u64 | write_to_file_bytes (const string *path, const string *contents, const u64 bytes) |
Write bytes from @contents to a file at path. | |
Gets the size of a file at path.
Through opening the file and then running file_size_stream().
path must be valid and cannot be null.| path | The path to the file to get the size of. |
| u64 file_size_stream | ( | FILE * | stream | ) |
Gets the size of a file from a file stream.
Safe macros for fseek() and ftell() thats compatible across platforms.
By reading the size through fseek64() and ftell64(). Which are aliases:
stream must be valid, preferably open with "rb" and cannot be null.| stream | The file stream to get the size of. |
Reads the contents of a file at path into a string.
Opens the file, reads the entire file 'til EOF with read_file_from_stream(), then returns the result.
arena and path must be valid and cannot be null.| arena | For allocating the contents of the file. |
| path | The path to the file to read. |
Read bytes from a file path to string.
By opening the file, reading bytes into a block using read_file_from_stream_bytes(), then returning the result.
arena, path, and bytes must be valid and cannot be null.| arena | For allocating the contents of the file. |
| path | The path to the file to read. |
| bytes | The number of bytes to read. |
Reads the contents of a file from stream into a string.
Reads the entire file 'til EOF and stores it in a string, with the file content length in the len param using fread().
arena must be valid antd cannot be null.stream must be valid and cannot be null preferably open with "rb".| arena | For allocating the contents of the file. |
| stream | The file stream to read from. |
Read bytes from file stream to string.
By allocating a block using the arena that is bytes big and reading bytes into that block using fread().
arena, stream, and bytes must be valid and cannot be null.stream should be preferably open with "rb".| arena | For allocating the contents of the file. |
| stream | The file stream to read from. |
| bytes | The number of bytes to read. |
Write contents to file path.
By writing len characters from contents to the file at path using write_to_file_stream().
path and contents must be valid, and cannot be null.| path | The path to the file to write to. |
| contents | The string to write to the file. |
Write bytes from @contents to a file at path.
By writing bytes from contents to the file at path using write_to_file_stream_bytes(), and then returning the result.
path and contents must be valid, and cannot be null.| path | The path to the file to write to. |
| contents | The string to write to the file. |
Write contents to file stream.
By writing len characters from contents to that file thats associated with stream using fwrite().
stream and contents must be valid, and cannot be null.stream should be preferably open with "wb".| stream | The file stream to write to. |
| contents | The string to write to the file. |
Write bytes from contents to stream.
By writing bytes from contents to the file stream provided by stream using fwrite() .
stream, contents, and bytes must be valid, and cannot be null nor 0.stream should be preferably open with "wb".| stream | The file stream to write to. |
| contents | The string to write to the file. |
| bytes | The number of bytes to write. |