blob: 78f679a657c269743d9b7c3a06b141e78f68c79e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}
|