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.
 
 

55 lines
777 B

#include "util.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void fatal(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
exit(EXIT_FAILURE);
}
byte_arr_t *read_file(const char *filepath)
{
FILE *fp = fopen(filepath, "rb");
byte_arr_t *arr = NULL;
if (fp == NULL)
{
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;
}