#include <stdio.h>
-/* Errors */
-enum {
- LBX_ESUCCESS,
- LBX_EMAGIC,
- LBX_EEOF,
- LBX_ERANGE,
- LBX_EFORMAT,
+struct lbx_file_ops {
+ size_t (*read)(void *buf, size_t size, void *handle);
+ int (*seek)(void *handle, long offset, int whence);
+ long (*tell)(void *handle);
+ int (*eof) (void *handle);
};
-extern int lbx_errno;
+
+struct lbx_pipe_state {
+ FILE *f;
+ long offset;
+};
+
+/* Default I/O operations for ordinary files. */
+extern const struct lbx_file_ops lbx_default_fops;
+
+/* I/O operations for un-seekable files (e.g. pipes). */
+extern const struct lbx_file_ops lbx_pipe_fops;
+
+/* I/O operations for LBX archive members. */
+extern const struct lbx_file_ops lbx_arch_fops;
/* Opaque */
-typedef struct lbx_state LBX;
+typedef struct lbx_file_state LBXfile;
+
+struct lbx {
+ unsigned nfiles;
+};
struct lbx_statbuf {
const char *name;
};
/* Archive operations */
-LBX *lbx_fopen(FILE *, const char *);
-LBX *lbx_mopen(void *, size_t, const char *);
-void lbx_close(LBX *);
-size_t lbx_numfiles(LBX *);
+struct lbx *lbx_open(void *handle, const struct lbx_file_ops *fops,
+ int (*destructor)(void *handle), const char *name);
+struct lbx *lbx_fopen(const char *);
+struct lbx *lbx_mopen(void *, size_t, const char *);
+int lbx_close(struct lbx *);
/* File operations */
-int lbx_stat(LBX *, size_t, struct lbx_statbuf *);
-size_t lbx_extract(LBX *, size_t, FILE *);
-void *lbx_mmap(LBX *, size_t, size_t *);
-
-/* Misc operations */
-const char *lbx_strerror(void);
+int lbx_file_stat(struct lbx *lbx, unsigned fileno, struct lbx_statbuf *out);
+LBXfile *lbx_file_open(struct lbx *lbx, unsigned fileno);
+size_t lbx_file_read(LBXfile *f, void *buf, size_t n);
+int lbx_file_seek(LBXfile *f, long offset, int whence);
+long lbx_file_tell(LBXfile *f);
+int lbx_file_eof(LBXfile *f);
+void lbx_file_close(LBXfile *f);
#endif