static INDX_ROOT *_indx_get(BD_DISC *disc, const char *path) { BD_FILE_H *fp; INDX_ROOT *index; fp = disc_open_path(disc, path); if (!fp) { return NULL; } index = _indx_parse(fp); file_close(fp); return index; }
static MOBJ_OBJECTS *_mobj_get(BD_DISC *disc, const char *path) { BD_FILE_H *fp; MOBJ_OBJECTS *objects; fp = disc_open_path(disc, path); if (!fp) { return NULL; } objects = _mobj_parse(fp); file_close(fp); return objects; }
static BDID_DATA *_bdid_get(BD_DISC *disc, const char *path) { BD_FILE_H *fp; BDID_DATA *bdid; fp = disc_open_path(disc, path); if (!fp) { return NULL; } bdid = _bdid_parse(fp); file_close(fp); return bdid; }
BD_FILE_H *disc_open_file(BD_DISC *p, const char *dir, const char *file) { BD_FILE_H *fp; char *path; path = str_printf("%s" DIR_SEP "%s", dir, file); if (!path) { return NULL; } fp = disc_open_path(p, path); X_FREE(path); return fp; }
size_t disc_read_file(BD_DISC *disc, const char *dir, const char *file, uint8_t **data) { BD_FILE_H *fp; int64_t size; *data = NULL; if (dir) { fp = disc_open_file(disc, dir, file); } else { fp = disc_open_path(disc, file); } if (!fp) { return 0; } size = file_size(fp); if (size > 0 && size < BD_MAX_SSIZE) { *data = malloc((size_t)size); if (*data) { int64_t got = file_read(fp, *data, size); if (got != size) { BD_DEBUG(DBG_FILE | DBG_CRIT, "Error reading file %s from %s\n", file, dir); X_FREE(*data); size = 0; } } else { size = 0; } } else { size = 0; } file_close(fp); return (size_t)size; }