added assfile
[raydungeon] / libs / assfile / assfile.h
1 /*
2 assfile - library for accessing assets with an fopen/fread-like interface
3 Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef ASSFILE_H_
19 #define ASSFILE_H_
20
21 #include <stdlib.h>
22
23 #ifndef ASSFILE_IMPL_H_
24 typedef void ass_file;
25 #endif
26
27 struct ass_fileops {
28         void *udata;
29         void *(*open)(const char *fname, void *udata);
30         void (*close)(void *fp, void *udata);
31         long (*seek)(void *fp, long offs, int whence, void *udata);
32         long (*read)(void *fp, void *buf, long size, void *udata);
33 };
34
35 /* options (ass_set_option/ass_get_option) */
36 enum {
37         ASS_OPEN_FALLTHROUGH    /* try all matching handlers if the first fails to open the file */
38 };
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 extern int ass_errno;
45
46 void ass_set_option(int opt, int val);
47 int ass_get_option(int opt);
48
49 /* add a handler for a specific path prefixes. 0 matches every path */
50 int ass_add_path(const char *prefix, const char *path);
51 int ass_add_archive(const char *prefix, const char *arfile);
52 int ass_add_url(const char *prefix, const char *url);
53 int ass_add_user(const char *prefix, struct ass_fileops *cb);
54 void ass_clear(void);
55
56 ass_file *ass_fopen(const char *fname, const char *mode);
57 void ass_fclose(ass_file *fp);
58 long ass_fseek(ass_file *fp, long offs, int whence);
59 long ass_ftell(ass_file *fp);
60
61 size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp);
62
63 /* convenience functions, derived from the above */
64 int ass_fgetc(ass_file *fp);
65 char *ass_fgets(char *s, int size, ass_file *fp);
66
67 #ifdef __cplusplus
68 }
69 #endif
70
71
72 #endif  /* ASSFILE_H_ */