archeus/src/std/io.c
herbglitch db1adbb838 first
2022-10-27 15:16:54 -06:00

28 lines
533 B
C

#include "arc/std/io.h"
#include "arc/std/errno.h"
#include <stdio.h>
#include <stdlib.h>
int32_t ARC_IO_FileToStr(const char *path, char **data, uint64_t *size){
FILE *file = fopen(path, "rb");
if(!file){ return ARC_ERRNO_NULL; }
fseek(file, 0L, SEEK_END);
*size = ftell(file);
rewind(file);
*data = (char *) calloc(1, *size + 1);
if(!*data){
fclose(file);
return ARC_ERRNO_NULL;
}
if(1 != fread(*data, *size, 1, file)){
fclose(file);
return ARC_ERRNO_COPY;
}
fclose(file);
return 0;
}