An emulator, assembler, and disassembler for the Sega Game Gear
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #include <errno.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/stat.h>
  8. #include "rom.h"
  9. /*
  10. Create and return a ROM object located at the given path. Return NULL if
  11. there was an error; errno will be set appropriately.
  12. */
  13. ROM* rom_open(const char *path)
  14. {
  15. ROM *rom;
  16. FILE* fp;
  17. struct stat s;
  18. if (!(fp = fopen(path, "r")))
  19. return NULL;
  20. if (fstat(fileno(fp), &s)) {
  21. fclose(fp);
  22. return NULL;
  23. }
  24. if (!(s.st_mode & S_IFREG)) {
  25. errno = (s.st_mode & S_IFDIR) ? EISDIR : ENOENT;
  26. fclose(fp);
  27. return NULL;
  28. }
  29. if (!(rom = malloc(sizeof(ROM)))) {
  30. fclose(fp);
  31. return NULL;
  32. }
  33. rom->name = malloc(sizeof(char) * (strlen(path) + 1));
  34. if (!rom->name) {
  35. fclose(fp);
  36. return NULL;
  37. }
  38. strcpy(rom->name, path);
  39. // TODO: load data from file into a buffer
  40. fclose(fp);
  41. return rom;
  42. }
  43. /*
  44. Free a ROM object previously created with rom_open().
  45. */
  46. void rom_close(ROM *rom)
  47. {
  48. free(rom);
  49. }