diff options
author | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-02-24 11:43:13 +1100 |
---|---|---|
committer | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-02-24 11:43:13 +1100 |
commit | b047be5252aeb981faea077409c1768fda0301d9 (patch) | |
tree | 43925d4f4ef3aed59a147746d918c34e66fe91a6 /src/platform | |
parent | a67df4d18655e58d8544e91cde546122f41cb492 (diff) |
xmake init with shared/static lib
Diffstat (limited to 'src/platform')
-rw-r--r-- | src/platform/file.c | 29 | ||||
-rw-r--r-- | src/platform/file.h | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/platform/file.c b/src/platform/file.c new file mode 100644 index 0000000..497a95c --- /dev/null +++ b/src/platform/file.c @@ -0,0 +1,29 @@ +#include "file.h" + +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +const char *string_from_file(const char *path) { + FILE *f = fopen(path, "rb"); + if (f == NULL) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + if (ferror(f)) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + rewind(f); + + char *string = malloc(fsize + 1); + fread(string, fsize, 1, f); + fclose(f); + + string[fsize] = '\0'; + + return string; +}
\ No newline at end of file diff --git a/src/platform/file.h b/src/platform/file.h new file mode 100644 index 0000000..b965ceb --- /dev/null +++ b/src/platform/file.h @@ -0,0 +1,11 @@ +/** + * @file file.h + * @brief File I/O utilities + * @date 2024-02-24 + * @copyright Copyright (c) 2024 + */ +#pragma once + +#include <stdbool.h> + +const char* string_from_file(const char* path); |