|
- #include <string.h>
-
- #include "ines.h"
- #include "nes.h"
-
-
- int ines_check_mem(void* mem) {
- int status = 0;
- ines_Header *hdr = (ines_Header*)mem;
-
- if (0 != memcmp(hdr->magic, ines_magic, sizeof(hdr->magic))) {
- INES_ERR("Bad file magic: expected '%.4s', got '%.4s'",
- ines_magic, hdr->magic);
- status = -1;
- }
-
- return status;
- }
-
- int ines_check(ines_Header* ret, FILE* file) {
- int status = 0;
- ines_Header hdr = {0};
-
- if (1 != fread(&hdr, sizeof(ines_Header), 1, file)) {
- INES_ERR("Failed to read header");
- status = -1;
- }
-
- if (0 == status) {
- status = ines_check_mem(&hdr);
- }
-
- if (0 == status && NULL != ret) {
- *ret = hdr;
- }
-
- return status;
- }
|