+ rc = fops->read(buf, want, f->lbx->f);
+ f->offset += rc;
+
+ if (want < n || (rc < want && fops->eof(f->lbx->f)))
+ f->eof = 1;
+ return rc;
+}
+
+int lbx_file_seek(struct lbx_file_state *f, long offset, int whence)
+{
+ const struct lbx_file_ops *fops = f->lbx->fops;
+ unsigned long pos;
+
+ switch (whence) {
+ case SEEK_CUR:
+ pos = f->offset + offset;
+ break;
+ case SEEK_SET:
+ pos = offset;
+ break;
+ case SEEK_END:
+ pos = f->limit + offset;
+ break;
+ default:
+ lbx_error_raise(LBX_EINVAL);
+ return -1;
+ }
+
+ 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)
+ return -1;
+
+ f->offset = pos;
+ f->lbx->last_file = f;
+ f->eof = 0;
+
+ return 0;
+}
+
+long lbx_file_tell(struct lbx_file_state *f)
+{
+ return f->offset;
+}
+
+int lbx_file_eof(struct lbx_file_state *f)
+{
+ return f->eof;
+}
+
+void lbx_file_close(struct lbx_file_state *f)
+{
+ if (f->lbx->last_file == f)
+ f->lbx->last_file = NULL;
+ free(f);