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.

40 lines
610 B

  1. #include "util.h"
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. void fatal(const char *fmt, ...) {
  6. va_list args;
  7. va_start(args, fmt);
  8. vfprintf(stderr, fmt, args);
  9. va_end(args);
  10. exit(EXIT_FAILURE);
  11. }
  12. byte_arr_t *read_file(const char *filepath) {
  13. FILE *fp = fopen(filepath, "rb");
  14. byte_arr_t *arr = NULL;
  15. fseek(fp, 0, SEEK_END);
  16. const long size = ftell(fp);
  17. if (size < 0) {
  18. goto end;
  19. }
  20. arr = malloc(sizeof *arr + size);
  21. if (arr == NULL) {
  22. goto end;
  23. }
  24. arr->size = size;
  25. rewind(fp);
  26. fread(arr->data, 1, size, fp);
  27. end:
  28. fclose(fp);
  29. return arr;
  30. }