static int load_module(xmp_context opaque, HIO_HANDLE *h, struct list_head *tmpfiles_list) { struct context_data *ctx = (struct context_data *)opaque; struct module_data *m = &ctx->m; int i, ret; int test_result, load_result; load_prologue(ctx); D_(D_WARN "load"); test_result = load_result = -1; for (i = 0; format_loader[i] != NULL; i++) { hio_seek(h, 0, SEEK_SET); test_result = format_loader[i]->test(h, NULL, 0); if (test_result == 0) { hio_seek(h, 0, SEEK_SET); D_(D_WARN "load format: %s", format_loader[i]->name); load_result = format_loader[i]->loader(m, h, 0); break; } } if (test_result == 0 && load_result == 0) set_md5sum(h, m->md5); hio_close(h); if (tmpfiles_list != NULL) unlink_tempfiles(tmpfiles_list); if (test_result < 0) { free(m->basename); free(m->dirname); return -XMP_ERROR_FORMAT; } if (load_result < 0) { xmp_release_module(opaque); return -XMP_ERROR_LOAD; } str_adj(m->mod.name); load_epilogue(ctx); ret = prepare_scan(ctx); if (ret < 0) return ret; scan_sequences(ctx); ctx->state = XMP_STATE_LOADED; return 0; }
static int module_load(HIO_HANDLE* h, struct context_data *ctx, const struct format_loader* format) { struct module_data *m = &ctx->m; hio_seek(h, 0, SEEK_SET); if (format->loader(m, h, 0) < 0) return -XMP_ERROR_LOAD; str_adj(m->mod.name); str_adj(m->mod.author); load_epilogue(ctx); if (prepare_scan(ctx) < 0) return -XMP_ERROR_LOAD; scan_sequences(ctx); ctx->state = XMP_STATE_LOADED; set_md5sum(h, m->md5); return 0; }
int xmp_load_module(xmp_context opaque, char *path) { struct context_data *ctx = (struct context_data *)opaque; struct module_data *m = &ctx->m; HIO_HANDLE *h; struct stat st; struct list_head tmpfiles_list; int test_result, load_result; int i, ret; D_(D_WARN "path = %s", path); if (stat(path, &st) < 0) return -XMP_ERROR_SYSTEM; #ifndef _MSC_VER if (S_ISDIR(st.st_mode)) { errno = EISDIR; return -XMP_ERROR_SYSTEM; } #endif if ((h = hio_open_file(path, "rb")) == NULL) return -XMP_ERROR_SYSTEM; INIT_LIST_HEAD(&tmpfiles_list); D_(D_INFO "decrunch"); if (decrunch(&tmpfiles_list, &h->f, &path, DECRUNCH_MAX) < 0) goto err_depack; if (hio_stat(h, &st) < 0) goto err_depack; if (st.st_size < 256) { /* get size after decrunch */ hio_close(h); unlink_tempfiles(&tmpfiles_list); return -XMP_ERROR_FORMAT; } if (ctx->state > XMP_STATE_UNLOADED) xmp_release_module(opaque); m->dirname = get_dirname(path); if (m->dirname == NULL) return -XMP_ERROR_SYSTEM; m->basename = get_basename(path); if (m->basename == NULL) return -XMP_ERROR_SYSTEM; m->filename = path; /* For ALM, SSMT, etc */ m->size = st.st_size; load_prologue(ctx); D_(D_WARN "load"); test_result = load_result = -1; for (i = 0; format_loader[i] != NULL; i++) { hio_seek(h, 0, SEEK_SET); test_result = format_loader[i]->test(h, NULL, 0); if (test_result == 0) { hio_seek(h, 0, SEEK_SET); D_(D_WARN "load format: %s", format_loader[i]->name); load_result = format_loader[i]->loader(m, h, 0); break; } } set_md5sum(h, m->md5); hio_close(h); unlink_tempfiles(&tmpfiles_list); if (test_result < 0) { free(m->basename); free(m->dirname); return -XMP_ERROR_FORMAT; } if (load_result < 0) { xmp_release_module(opaque); return -XMP_ERROR_LOAD; } str_adj(m->mod.name); if (!*m->mod.name) { strncpy(m->mod.name, m->basename, XMP_NAME_SIZE); } load_epilogue(ctx); ret = prepare_scan(ctx); if (ret < 0) return ret; scan_sequences(ctx); ctx->state = XMP_STATE_LOADED; return 0; err_depack: hio_close(h); unlink_tempfiles(&tmpfiles_list); return -XMP_ERROR_DEPACK; }
static int load_module(xmp_context opaque, HIO_HANDLE *h) { struct context_data *ctx = (struct context_data *)opaque; struct module_data *m = &ctx->m; struct xmp_module *mod = &m->mod; int i, j, ret; int test_result, load_result; load_prologue(ctx); D_(D_WARN "load"); test_result = load_result = -1; for (i = 0; format_loader[i] != NULL; i++) { hio_seek(h, 0, SEEK_SET); D_(D_WARN "test %s", format_loader[i]->name); test_result = format_loader[i]->test(h, NULL, 0); if (test_result == 0) { hio_seek(h, 0, SEEK_SET); D_(D_WARN "load format: %s", format_loader[i]->name); load_result = format_loader[i]->loader(m, h, 0); break; } } #ifndef LIBXMP_CORE_PLAYER if (test_result == 0 && load_result == 0) set_md5sum(h, m->md5); #endif if (test_result < 0) { free(m->basename); free(m->dirname); return -XMP_ERROR_FORMAT; } if (load_result < 0) { goto err_load; } /* Sanity check */ if (mod->chn > XMP_MAX_CHANNELS || mod->len > XMP_MAX_MOD_LENGTH) { goto err_load; } /* Sanity check */ if (mod->xxp == NULL) { goto err_load; } for (i = 0; i < mod->pat; i++) { if (mod->xxp[i] == NULL) { goto err_load; } for (j = 0; j < mod->chn; j++) { int t = mod->xxp[i]->index[j]; if (t < 0 || t >= mod->trk || mod->xxt[t] == NULL) { goto err_load; } } } adjust_string(mod->name); load_epilogue(ctx); ret = prepare_scan(ctx); if (ret < 0) { xmp_release_module(opaque); return ret; } scan_sequences(ctx); ctx->state = XMP_STATE_LOADED; return 0; err_load: xmp_release_module(opaque); return -XMP_ERROR_LOAD; }