]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbx.c
test: Fix up regression test script.
[liblbx.git] / src / lbx.c
index d75a1232485d67b2e1660e40ad03958a132ab4db..fc52680c47c0a57c19fec6a074de4ff0af5f884c 100644 (file)
--- 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)