|
htils 1
A small set of utilities for C programming.
|
#include <ctype.h>#include <dirent.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <htils/assert.h>#include <htils/darray.h>#include <htils/dotenv.h>#include <htils/file.h>#include <htils/path.h>#include <htils/string.h>Functions | |
| static b32 | is_env_file (const cstr *path_name) |
| Check if a path is a .env file. | |
| static string * | find_first_env_file (arena_t *arena, const string *path) |
| Find the first .env file in a directory. | |
| static void | to_upper (string_slice str_slice) |
| Convert a string to uppercase. | |
| static void | trim_quotes (string_slice *str) |
| Trim quotes from a string. | |
| static b32 | parse_line (arena_t *arena, string *line, string **key, string **value) |
| Parse a line of a .env file. | |
| i32 | htils_dotenv_load (arena_t *arena, const string *path) |
| Load a dotenv file, or a path with a .env file within it. | |
Find the first .env file in a directory.
Crawling through a directory and return the path of the first known .env file.
| arena | The arena to allocate from. |
| path | The path to find the .env file in. |
arena, and path must be valid and cannot be null.Load a dotenv file, or a path with a .env file within it.
| path | The path where a .env file is located or the explicit relative or complete path to the .env file |
| arena | The arena to allocate from. |
path, and arena must be valid, and not null.path must be a valid path.Check if a path is a .env file.
By first retrieveing its extension, and then verifying that the extension is .env.
| arena | The arena to allocate from. |
| path | The path to check. |
arena and path must be valid and cannot be null.Parse a line of a .env file.
By checking if the line is empty, a comment, or a new_line before trimming whitespace, making sure the key is upper case, and trimming quotes from the value, then setting the key and line to the parsed values.
| arena | The arena to allocate from. |
| line | The line to parse. |
| key | The key of the line. |
| value | The value of the line. |
arena, line, must be valid and cannot be null.key and value must be valid pointers that you can overwrite.
|
static |
Convert a string to uppercase.
By iterating through the string, and converting each character to it's uppercase counterpart.
| str | The string to convert. |
str must be valid and cannot be null.
|
static |
Trim quotes from a string.
By checking if the first and last characters are quotes, and then trims and memmoves as needed.
| str | The string to trim. |
str must be valid and cannot be null.