acl_readTextFile uses FILE* now
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
#ifndef _acl_file_h
|
#ifndef _acl_file_h
|
||||||
#define _acl_file_h
|
#define _acl_file_h
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
char* acl_ReadTextFile(const char *filePath, bool *sucess);
|
#include <stdio.h>
|
||||||
|
char* acl_ReadTextFile(FILE *file, bool *sucess);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
15
src/file.c
15
src/file.c
@ -1,25 +1,22 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
char* acl_ReadTextFile(const char *filePath, bool *sucess){
|
char* acl_ReadTextFile(FILE *file, bool *sucess){
|
||||||
FILE *fp = fopen(filePath, "rb");
|
|
||||||
size_t lSize;
|
size_t lSize;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
if(!fp) {
|
if(!file) {
|
||||||
*sucess = false;
|
*sucess = false;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
fseek(fp, 0L, SEEK_END);
|
fseek(file, 0L, SEEK_END);
|
||||||
lSize = ftell(fp);
|
lSize = ftell(file);
|
||||||
rewind(fp);
|
rewind(file);
|
||||||
buffer = malloc(lSize + 1);
|
buffer = malloc(lSize + 1);
|
||||||
if(!buffer) {
|
if(!buffer) {
|
||||||
fclose(fp);
|
|
||||||
*sucess = false;
|
*sucess = false;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
size_t readReturn = fread(buffer, lSize, 1, fp);
|
size_t readReturn = fread(buffer, lSize, 1, file);
|
||||||
fclose(fp);
|
|
||||||
*sucess = readReturn == 1;
|
*sucess = readReturn == 1;
|
||||||
buffer[lSize] = '\0';
|
buffer[lSize] = '\0';
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user