X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/32081e3bb50124d451a660872f6dff57232e5172..ff5bd81012bba4202487c9a5bf7649bd63ca4bae:/src/lbx.c?ds=sidebyside diff --git a/src/lbx.c b/src/lbx.c index d75a123..fc52680 100644 --- a/src/lbx.c +++ b/src/lbx.c @@ -165,21 +165,6 @@ eof: return NULL; } -struct lbx_state *lbx_open(const char *path) -{ - struct lbx_state *new = NULL; - FILE *f; - - if ((f = fopen(path, "rb"))) { - const char *name = strrchr(path, '/'); - new = lbx_fopen(f, name ? name+1 : path); - } else { - lbx_errno = -errno; - } - - return new; -} - size_t lbx_numfiles(struct lbx_state *lbx) { return lbx->nfiles; @@ -267,51 +252,18 @@ size_t lbx_extract(struct lbx_state *lbx, size_t index, FILE *of) return _lbx_fextract(lbx, base, len, of); } -void *lbx_mmap(struct lbx_state *lbx, size_t index, size_t *len) +int lbx_close(struct lbx_state *lbx) { - unsigned char *mapping; - struct stat statbuf; - size_t base; + int rc = 0; - if (index >= lbx->nfiles) { - lbx_errno = LBX_ERANGE; - return NULL; - } - - base = lbx->offsets[index]; - *len = lbx->offsets[index+1] - lbx->offsets[index]; - - if (lbx->mem) - return lbx->mem + base; - - if (fstat(fileno(lbx->f), &statbuf) == -1) { - lbx_errno = -errno; - return NULL; - } - - mapping = mmap(NULL, statbuf.st_size, PROT_READ, 0, fileno(lbx->f), 0); - if (mapping == MAP_FAILED) { - lbx_errno = -errno; - return NULL; - } - - lbx->mem = mapping; - lbx->memsize = statbuf.st_size; - return mapping + base; -} - -void lbx_close(struct lbx_state *lbx) -{ - if (!lbx) return; + if (!lbx) + return 0; - if (lbx->f) { - fclose(lbx->f); - if (lbx->mem) { - munmap(lbx->mem, lbx->memsize); - } - } + if (lbx->f) + rc = fclose(lbx->f); free(lbx); + return rc; } const char *lbx_strerror(void)