]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbx.c
Trivial manual fixes.
[liblbx.git] / src / lbx.c
index a2d37961a77d33b95d8761a5a1216913ce4e9d33..8080b67f3f74c3b747a76c205e107fe5c7ff51c3 100644 (file)
--- a/src/lbx.c
+++ b/src/lbx.c
@@ -1,7 +1,7 @@
 /*
  *  2ooM: The Master of Orion II Reverse Engineering Project
  *  Library for working with LBX archive files.
- *  Copyright © 2006-2010, 2013 Nick Bowler
+ *  Copyright © 2006-2010, 2013-2014 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ struct lbx_priv {
 
        struct lbx_file_state *last_file;
 
-       unsigned long offsets[];
+       unsigned long offsets[FLEXIBLE_ARRAY_MEMBER];
 };
 
 struct lbx_file_state {
@@ -51,7 +51,7 @@ struct lbx_file_state {
        int eof;
 };
 
-static struct lbx_priv *lbx_init(unsigned char hdr[static LBX_HDR_SIZE])
+static struct lbx_priv *lbx_init(unsigned char *hdr)
 {
        unsigned short nfiles  = unpack_16_le(hdr+0);
        unsigned long  magic   = unpack_32_le(hdr+2);
@@ -191,7 +191,7 @@ int lbx_file_stat(struct lbx *pub, unsigned fileno, struct lbx_statbuf *buf)
        static char str[256]; /* FIXME */
 
        if (fileno >= lbx->pub.nfiles) {
-               lbx_error_raise(LBX_ENOENT);
+               lbx_error_raise(LBX_EINVAL);
                buf->name = NULL;
                return -1;
        }
@@ -221,7 +221,7 @@ struct lbx_file_state *lbx_file_open(struct lbx *pub, unsigned fileno)
        struct lbx_file_state *state;
 
        if (fileno >= lbx->pub.nfiles) {
-               lbx_error_raise(LBX_ENOENT);
+               lbx_error_raise(LBX_EINVAL);
                return NULL;
        }
 
@@ -262,8 +262,13 @@ size_t lbx_file_read(struct lbx_file_state *f, void *buf, size_t n)
        rc = fops->read(buf, want, f->lbx->f);
        f->offset += rc;
 
-       if (want < n || (rc < want && fops->eof(f->lbx->f)))
+       if (rc < want) {
+               if (fops->eof(f->lbx->f))
+                       lbx_error_raise(LBX_EEOF);
+       } else if (rc < n) {
                f->eof = 1;
+       }
+
        return rc;
 }
 
@@ -282,10 +287,15 @@ int lbx_file_seek(struct lbx_file_state *f, long offset, int whence)
        case SEEK_END:
                pos = f->limit + offset;
                break;
+       default:
+               lbx_error_raise(LBX_EINVAL);
+               return -1;
        }
 
-       if (pos > f->limit)
+       if (pos > f->limit) {
+               lbx_error_raise(LBX_EINVAL);
                return -1;
+       }
 
        f->lbx->last_file = NULL;
        if (fops->seek(f->lbx->f, f->base + pos, SEEK_SET) != 0)