diff options
Diffstat (limited to 'src/io.c')
| -rw-r--r-- | src/io.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c new file mode 100644 index 0000000..78f679a --- /dev/null +++ b/src/io.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdbool.h> + +bool ReadFile(const char * const path, const size_t n, char * const buffer) { + FILE *fp = fopen(path, "r"); + if (fp == NULL) { + perror("ReadFile: fopen"); + return false; + } + + int j = 0; + size_t i = 0; + for (; i < n - 1; i++) { + j = fgetc(fp); + if (j == EOF) { + break; + } + buffer[i] = (char)j; + } + + buffer[i] = '\0'; + + bool ret = (!ferror(fp) && feof(fp)); + fclose(fp); + return ret; +} + |
