ReadTecxtFile

This commit is contained in:
2020-06-21 22:24:49 +02:00
parent 7f968cba8e
commit 04fbaa0cf5
5 changed files with 55 additions and 7 deletions

28
src/file.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
char* acl_ReadFileString(char *filePath, bool *sucess){
FILE *fp = fopen(filePath, "rb");
size_t lSize;
char *buffer;
if(!fp) {
*sucess = false;
return buffer;
}
fseek(fp, 0L, SEEK_END);
lSize = ftell(fp);
rewind(fp);
buffer = malloc(lSize + 1);
if(!buffer) {
fclose(fp);
*sucess = false;
return buffer;
}
size_t readReturn = fread(buffer, lSize, 1, fp);
fclose(fp);
if(readReturn != 1) {
*sucess = false;
}
*sucess = true;
return buffer;
}