Base/platform/src-c/fs/quick.c

37 lines
718 B
C
Raw Normal View History

2024-01-01 18:24:55 +00:00
#include <librr/fs/quick.h>
#include <stdio.h>
#include <stdlib.h>
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;
}