Debian Codegraph @

libs/zziplib/zziplib-src/zzip/plugin.h

raw
1 /*
2 * Author:
3 * Guido Draheim <[email protected]>
4 *
5 * Copyright (c) Guido Draheim, use under copyleft
6 *
7 * the interfaces for the plugin_io system
8 *
9 * Using the following you can provide your own file I/O functions to
10 * e.g. read data directly from memory, provide simple
11 * "encryption"/"decryption" of on-disk .zip-files...
12 * Note that this currently only provides a subset of the functionality
13 * in zziplib. It does not attempt to provide any directory functions,
14 * but if your program 1) only uses ordinary on-disk files and you
15 * just want this for file obfuscation, or 2) you only access your
16 * .zip archives using zzip_open & co., this is sufficient.
17 *
18 * Currently the default io are the POSIX functions, except
19 * for 'filesize' that is zziplibs own provided zzip_filesize function,
20 * using standard POSIX fd's. You are however free to replace this with
21 * whatever data type you need, so long as you provide implementations
22 * for all the functions, and the data type fits an int.
23 *
24 * all functions receiving ext_io are able to cope with both arguments
25 * set to zero which will let them default to a ZIP ext and posix io.
26 */
27 #ifndef _ZZIP_PLUGIN_H /* zzip-io.h */
28 #define _ZZIP_PLUGIN_H 1
29
30 #include <zzip/zzip.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* we have renamed zzip_plugin_io.use_mmap to zzip_plugin_io.sys */
37 #define ZZIP_PLUGIN_IO_SYS 1
38
39 struct zzip_plugin_io { /* use "zzip_plugin_io_handlers" in applications !! */
40 int (*open)(zzip_char_t* name, int flags, ...);
41 int (*close)(int fd);
42 zzip_ssize_t (*read)(int fd, void* buf, zzip_size_t len);
43 zzip_off_t (*seeks)(int fd, zzip_off_t offset, int whence);
44 zzip_off_t (*filesize)(int fd);
45 long sys;
46 long type;
47 zzip_ssize_t (*write)(int fd, _zzip_const void* buf, zzip_size_t len);
48 };
49
50 typedef union _zzip_plugin_io
51 {
52 struct zzip_plugin_io fd;
53 struct { void* padding[8]; } ptr;
54 } zzip_plugin_io_handlers;
55
56 #define _zzip_plugin_io_handlers zzip_plugin_io_handlers
57
58 /* for backward compatibility, add the following to your application code:
59 * #ifndef _zzip_plugin_io_handlers
60 * #define _zzip_plugin_io_handlers struct zzip_plugin_io
61 */
62 typedef zzip_plugin_io_handlers* zzip_plugin_io_handlers_t;
63
64 #ifdef ZZIP_LARGEFILE_RENAME
65 #define zzip_filesize zzip_filesize64
66 #define zzip_get_default_io zzip_get_default_io64
67 #define zzip_init_io zzip_init_io64
68 #endif
69
70 _zzip_export zzip_off_t
71 zzip_filesize(int fd);
72
73 /* get the default file I/O functions.
74 * This functions returns a pointer to an internal static structure.
75 */
76 _zzip_export zzip_plugin_io_t zzip_get_default_io(void);
77
78 /*
79 * Initializes a zzip_plugin_io_t to the zziplib default io.
80 * This is useful if you only want to override e.g. the 'read' function.
81 * all zzip functions that can receive a zzip_plugin_io_t can
82 * handle a zero pointer in that place and default to posix io.
83 */
84 _zzip_export
85 int zzip_init_io(zzip_plugin_io_handlers_t io, int flags);
86
87 /* zzip_init_io flags : */
88 # define ZZIP_IO_USE_MMAP 1
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif