Compare commits
2 Commits
34274b0645
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a83de1b97b | |||
| 9cc252d0e6 |
@ -1,5 +1,6 @@
|
||||
#ifndef _acl_file_h
|
||||
#define _acl_file_h
|
||||
#include <stdbool.h>
|
||||
char* acl_ReadTextFile(const char *filePath, bool *sucess);
|
||||
#include <stdio.h>
|
||||
char* acl_ReadTextFile(FILE *file, bool *sucess);
|
||||
#endif
|
||||
|
||||
@ -35,7 +35,7 @@ void* acl_arraylist_append_ptr(void *arraylist_void, void **append_element) {
|
||||
union acl_arraylist_meta *arraylist = arraylist_void;
|
||||
--arraylist;
|
||||
if(arraylist->len == arraylist->cap) {
|
||||
acl_arraylist_resize(arraylist, 10);
|
||||
arraylist = acl_arraylist_resize(arraylist, 10);
|
||||
if(arraylist == NULL) return NULL;
|
||||
}
|
||||
*append_element = (char*)(arraylist + 1) + arraylist->sizeof_one_element * arraylist->len;
|
||||
|
||||
15
src/file.c
15
src/file.c
@ -1,25 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
char* acl_ReadTextFile(const char *filePath, bool *sucess){
|
||||
FILE *fp = fopen(filePath, "rb");
|
||||
char* acl_ReadTextFile(FILE *file, bool *sucess){
|
||||
size_t lSize;
|
||||
char *buffer;
|
||||
if(!fp) {
|
||||
if(!file) {
|
||||
*sucess = false;
|
||||
return buffer;
|
||||
}
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
lSize = ftell(fp);
|
||||
rewind(fp);
|
||||
fseek(file, 0L, SEEK_END);
|
||||
lSize = ftell(file);
|
||||
rewind(file);
|
||||
buffer = malloc(lSize + 1);
|
||||
if(!buffer) {
|
||||
fclose(fp);
|
||||
*sucess = false;
|
||||
return buffer;
|
||||
}
|
||||
size_t readReturn = fread(buffer, lSize, 1, fp);
|
||||
fclose(fp);
|
||||
size_t readReturn = fread(buffer, lSize, 1, file);
|
||||
*sucess = readReturn == 1;
|
||||
buffer[lSize] = '\0';
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user