]> git.draconx.ca Git - liblbx.git/blob - src/lbx.h
liblbx: Remove tell function from lbx_file_ops.
[liblbx.git] / src / lbx.h
1 #ifndef LBX_H_
2 #define LBX_H_
3
4 #include <stdio.h>
5
6 struct lbx_file_ops {
7         size_t (*read)(void *buf, size_t size, void *handle);
8         int    (*seek)(void *handle, long offset, int whence);
9         int    (*eof) (void *handle);
10 };
11
12 struct lbx_pipe_state {
13         FILE *f;
14         long offset;
15 };
16
17 /* Default I/O operations for ordinary files. */
18 extern const struct lbx_file_ops lbx_default_fops;
19
20 /* I/O operations for un-seekable files (e.g. pipes). */
21 extern const struct lbx_file_ops lbx_pipe_fops;
22
23 /* I/O operations for LBX archive members. */
24 extern const struct lbx_file_ops lbx_arch_fops;
25
26 /* Opaque */
27 typedef struct lbx_file_state LBXfile;
28
29 struct lbx {
30         unsigned nfiles;
31 };
32
33 struct lbx_statbuf {
34         const char *name;
35         size_t size;
36 };
37
38 /* Archive operations */
39 struct lbx *lbx_open(void *handle, const struct lbx_file_ops *fops,
40                      int (*destructor)(void *handle), const char *name);
41 struct lbx *lbx_fopen(const char *);
42 int lbx_close(struct lbx *);
43
44 /* File operations */
45 int      lbx_file_stat(struct lbx *lbx, unsigned fileno, struct lbx_statbuf *out);
46 LBXfile *lbx_file_open(struct lbx *lbx, unsigned fileno);
47 size_t   lbx_file_read(LBXfile *f, void *buf, size_t n);
48 int      lbx_file_seek(LBXfile *f, long offset, int whence);
49 long     lbx_file_tell(LBXfile *f);
50 int      lbx_file_eof(LBXfile *f);
51 void     lbx_file_close(LBXfile *f);
52
53 #endif