config and string reworked, hashtable updated to use arc_errno

This commit is contained in:
herbglitch 2023-01-17 01:59:08 -07:00
parent 0bbce28469
commit f8d987da8e
12 changed files with 1121 additions and 657 deletions

View file

@ -1,28 +1,36 @@
#include "arc/std/io.h"
#include "arc/std/errno.h"
#include "arc/std/string.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; }
void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
FILE *file = fopen(path->data, "rb");
if(!file){
return;
arc_errno = ARC_ERRNO_NULL;
}
fseek(file, 0L, SEEK_END);
*size = ftell(file);
rewind(file);
fseek(file, 0L, SEEK_END);
uint64_t length = ftell(file);
rewind(file);
char *fileData = (char *) calloc(1, length + 1);
if(fileData == NULL){
fclose(file);
arc_errno = ARC_ERRNO_NULL;
*data = NULL;
return;
}
if(1 != fread(fileData, length, 1, file)){
fclose(file);
arc_errno = ARC_ERRNO_COPY;
*data = NULL;
return;
}
*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;
ARC_String_Create(data, fileData, length);
}