diff --git a/build.bash b/build.bash index 7b84843..4160509 100755 --- a/build.bash +++ b/build.bash @@ -6,7 +6,7 @@ GCC_ARGUMENTS="-std=c11 -Wall" MODULES=( "core" - "json" + "platform" ) # Arguments: @@ -41,16 +41,12 @@ function compile_folder() { done ar -rvs $PROJECT_ROOT/.build/$PROJECT_NAME-$1.a $OBJECTS_FOLDER/*.o + cd $PROJECT_ROOT } function compile_all_modules() { - for MODULE in $MODULES - do - echo "============ CURRENT MODULE: $MODULE ============" - compile_folder \ - "$MODULE" \ - "-I $PROJECT_ROOT/$MODULE/exports/" - done + compile_folder "core" "-I $PROJECT_ROOT/core/exports/" + compile_folder "platform" "-I $PROJECT_ROOT/core/exports/ -I $PROJECT_ROOT/platform/exports/" } case $1 in diff --git a/platform/exports/librr/fs/quick.h b/platform/exports/librr/fs/quick.h new file mode 100644 index 0000000..f037057 --- /dev/null +++ b/platform/exports/librr/fs/quick.h @@ -0,0 +1,10 @@ + +#ifndef RR_FS_QUICK_H +#define RR_FS_QUICK_H + +#include + +usz_t rr_get_file_length(const char *path); +void * rr_load_whole_file(const char *path); + +#endif // RR_FS_QUICK_H diff --git a/platform/src-c/fs/quick.c b/platform/src-c/fs/quick.c new file mode 100644 index 0000000..28a343b --- /dev/null +++ b/platform/src-c/fs/quick.c @@ -0,0 +1,36 @@ +#include +#include +#include + +usz_t rr_get_file_length(const char *path) +{ + FILE *file = fopen(path, "rb"); + if(file == NULL) + return 0; + + fseek(file, 0, SEEK_END); + usz_t length = ftell(file); + fclose(file); + + return length; +} + +void * rr_load_whole_file(const char *path) +{ + FILE *file = fopen(path, "rb"); + if(file == NULL) + return NULL; + + fseek(file, 0, SEEK_END); + usz_t length = ftell(file); + fseek(file, 0, SEEK_SET); + + char *data = malloc(length+1); + usz_t read_length = fread(data, length, 1, file); + if(read_length < length) + data = realloc(data, read_length); + + fclose(file); + + return data; +}