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