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