|
htils 1
A small set of utilities for C programming.
|
#include <stdio.h>#include <sys/stat.h>#include <htils/arena.h>#include <htils/basictypes.h>#include <htils/string.h>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.
Opens the file and defers to 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 fstat() and fileno() thats compatible across platforms.
By reading the size using fstat() by first converting the file stream into a file descriptor with fileno(). and then getting the stat structure's st_size field.
fstat() and fileno() 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 and defers to read_file_from_stream().
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, and path must be valid and cannot be null.bytes must be greater than 0.| 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 stream to EOF and returns it as a string, with the byte count in the string's len, using fread().
| 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 and stream must be valid and cannot be null.stream should be preferably open with "rb".bytes must be greater than 0.| 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.bytes must be greater than 0.| path | The path to the file to write to. |
| contents | The string to write to the file. |
| bytes | The number of bytes to write. |
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, and contents must be valid, and cannot be nullstream should be preferably open with "wb".bytes must be greater than 0.| stream | The file stream to write to. |
| contents | The string to write to the file. |
| bytes | The number of bytes to write. |