]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbx.c
liblbx: Correct EOF handling in lbx_file_read.
[liblbx.git] / src / lbx.c
index 30cd156c957e747392046f5c9f9b7637f0580fdc..f96344d2ce7cfc717796531f244d789414973021 100644 (file)
--- a/src/lbx.c
+++ b/src/lbx.c
@@ -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)