psx emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
631 B

#include "util.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
byte_arr_t *read_file(const char *filepath)
{
FILE *fp = fopen(filepath, "rb");
byte_arr_t *arr = NULL;
if (fp == NULL)
{
// TODO: Log correctly
fprintf(stderr, "%s: ", filepath);
perror("could not open");
goto end;
}
fseek(fp, 0, SEEK_END);
const long size = ftell(fp);
if (size < 0)
{
goto end;
}
arr = malloc(sizeof *arr + size);
if (arr == NULL)
{
goto end;
}
arr->size = size;
rewind(fp);
fread(arr->data, 1, size, fp);
end:
if (fp != NULL)
{
fclose(fp);
}
return arr;
}