fix method index entry for add_file_magic()
[imager.git] / iolayert.h
CommitLineData
0778adbf
TC
1#ifndef IMAGER_IOLAYERT_H
2#define IMAGER_IOLAYERT_H
3
4#ifndef _MSC_VER
5#include <unistd.h>
6#endif
7#include <sys/types.h>
f6d10024 8#include <stddef.h>
8d14daab 9#include <stdio.h>
0778adbf
TC
10
11typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
12
13#ifdef _MSC_VER
14typedef int ssize_t;
15#endif
16
17typedef struct i_io_glue_t i_io_glue_t;
18
19/* compatibility for now */
20typedef i_io_glue_t io_glue;
21
22/* Callbacks we give out */
23
24typedef ssize_t(*i_io_readp_t) (io_glue *ig, void *buf, size_t count);
25typedef ssize_t(*i_io_writep_t)(io_glue *ig, const void *buf, size_t count);
26typedef off_t (*i_io_seekp_t) (io_glue *ig, off_t offset, int whence);
2b405c9e 27typedef int (*i_io_closep_t)(io_glue *ig);
0778adbf
TC
28typedef ssize_t(*i_io_sizep_t) (io_glue *ig);
29
30typedef void (*i_io_closebufp_t)(void *p);
31typedef void (*i_io_destroyp_t)(i_io_glue_t *ig);
32
33
34/* Callbacks we get */
35
36typedef ssize_t(*i_io_readl_t) (void *p, void *buf, size_t count);
37typedef ssize_t(*i_io_writel_t)(void *p, const void *buf, size_t count);
38typedef off_t (*i_io_seekl_t) (void *p, off_t offset, int whence);
2b405c9e 39typedef int (*i_io_closel_t)(void *p);
0778adbf
TC
40typedef void (*i_io_destroyl_t)(void *p);
41typedef ssize_t(*i_io_sizel_t) (void *p);
42
43extern char *io_type_names[];
44
45
46
47/* Structures to describe data sources */
48
0778adbf 49struct i_io_glue_t {
6d5c85a2
TC
50 io_type type;
51 void *exdata;
0778adbf
TC
52 i_io_readp_t readcb;
53 i_io_writep_t writecb;
54 i_io_seekp_t seekcb;
55 i_io_closep_t closecb;
56 i_io_sizep_t sizecb;
57 i_io_destroyp_t destroycb;
6d5c85a2
TC
58 unsigned char *buffer;
59 unsigned char *read_ptr;
60 unsigned char *read_end;
61 unsigned char *write_ptr;
62 unsigned char *write_end;
63 size_t buf_size;
64
65 /* non-zero if we encountered EOF */
66 int buf_eof;
67
68 /* non-zero if we've seen an error */
69 int error;
70
71 /* if non-zero we do write buffering (enabled by default) */
72 int buffered;
ed60e785
TC
73
74 im_context_t context;
0778adbf
TC
75};
76
6d5c85a2
TC
77#define I_IO_DUMP_CALLBACKS 1
78#define I_IO_DUMP_BUFFER 2
79#define I_IO_DUMP_STATUS 4
80#define I_IO_DUMP_DEFAULT (I_IO_DUMP_BUFFER | I_IO_DUMP_STATUS)
0778adbf 81
6d5c85a2
TC
82#define i_io_type(ig) ((ig)->source.ig_type)
83#define i_io_raw_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
84#define i_io_raw_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
85#define i_io_raw_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
86#define i_io_raw_close(ig) ((ig)->closecb(ig))
87#define i_io_is_buffered(ig) ((int)((ig)->buffered))
88
89#define i_io_getc(ig) \
90 ((ig)->read_ptr < (ig)->read_end ? \
91 *((ig)->read_ptr++) : \
92 i_io_getc_imp(ig))
215d9ead
TC
93#define i_io_nextc(ig) \
94 ((void)((ig)->read_ptr < (ig)->read_end ? \
95 ((ig)->read_ptr++, 0) : \
96 i_io_getc_imp(ig)))
6d5c85a2
TC
97#define i_io_peekc(ig) \
98 ((ig)->read_ptr < (ig)->read_end ? \
99 *((ig)->read_ptr) : \
100 i_io_peekc_imp(ig))
101#define i_io_putc(ig, c) \
102 ((ig)->write_ptr < (ig)->write_end && !(ig)->error ? \
103 *(ig)->write_ptr++ = (c) : \
104 i_io_putc_imp(ig, (c)))
105#define i_io_eof(ig) \
106 ((ig)->read_ptr == (ig)->read_end && (ig)->buf_eof)
107#define i_io_error(ig) \
108 ((ig)->read_ptr == (ig)->read_end && (ig)->error)
0778adbf
TC
109
110#endif