This commit is contained in:
herbglitch 2022-10-27 15:16:54 -06:00
commit db1adbb838
35 changed files with 4408 additions and 0 deletions

28
src/std/io.c Normal file
View file

@ -0,0 +1,28 @@
#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;
}