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