Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 104 lines (81 sloc) 2.888 kb
0778adbf » Tony Cook
2006-03-22 More iolayers work:
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 » Tony Cook
2006-06-27 include stddef.h for size_t
8 #include <stddef.h>
8d14daab »
2011-06-14 switch to using size_t and i_img_dim strictly
9 #include <stdio.h>
0778adbf » Tony Cook
2006-03-22 More iolayers work:
10
11 typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
12
13 #ifdef _MSC_VER
14 typedef int ssize_t;
15 #endif
16
17 typedef struct i_io_glue_t i_io_glue_t;
18
19 /* compatibility for now */
20 typedef i_io_glue_t io_glue;
21
22 /* Callbacks we give out */
23
24 typedef ssize_t(*i_io_readp_t) (io_glue *ig, void *buf, size_t count);
25 typedef ssize_t(*i_io_writep_t)(io_glue *ig, const void *buf, size_t count);
26 typedef off_t (*i_io_seekp_t) (io_glue *ig, off_t offset, int whence);
2b405c9e » Tony Cook
2006-06-26 add support for file write plugins
27 typedef int (*i_io_closep_t)(io_glue *ig);
0778adbf » Tony Cook
2006-03-22 More iolayers work:
28 typedef ssize_t(*i_io_sizep_t) (io_glue *ig);
29
30 typedef void (*i_io_closebufp_t)(void *p);
31 typedef void (*i_io_destroyp_t)(i_io_glue_t *ig);
32
33
34 /* Callbacks we get */
35
36 typedef ssize_t(*i_io_readl_t) (void *p, void *buf, size_t count);
37 typedef ssize_t(*i_io_writel_t)(void *p, const void *buf, size_t count);
38 typedef off_t (*i_io_seekl_t) (void *p, off_t offset, int whence);
2b405c9e » Tony Cook
2006-06-26 add support for file write plugins
39 typedef int (*i_io_closel_t)(void *p);
0778adbf » Tony Cook
2006-03-22 More iolayers work:
40 typedef void (*i_io_destroyl_t)(void *p);
41 typedef ssize_t(*i_io_sizel_t) (void *p);
42
43 extern char *io_type_names[];
44
45
46
47 /* Structures to describe data sources */
48
49 struct i_io_glue_t {
6d5c85a2 »
2011-10-10 Merge the I/O buffering branch
50 io_type type;
51 void *exdata;
0778adbf » Tony Cook
2006-03-22 More iolayers work:
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 »
2011-10-10 Merge the I/O buffering branch
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;
0778adbf » Tony Cook
2006-03-22 More iolayers work:
73 };
74
6d5c85a2 »
2011-10-10 Merge the I/O buffering branch
75 #define I_IO_DUMP_CALLBACKS 1
76 #define I_IO_DUMP_BUFFER 2
77 #define I_IO_DUMP_STATUS 4
78 #define I_IO_DUMP_DEFAULT (I_IO_DUMP_BUFFER | I_IO_DUMP_STATUS)
0778adbf » Tony Cook
2006-03-22 More iolayers work:
79
6d5c85a2 »
2011-10-10 Merge the I/O buffering branch
80 #define i_io_type(ig) ((ig)->source.ig_type)
81 #define i_io_raw_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
82 #define i_io_raw_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
83 #define i_io_raw_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
84 #define i_io_raw_close(ig) ((ig)->closecb(ig))
85 #define i_io_is_buffered(ig) ((int)((ig)->buffered))
86
87 #define i_io_getc(ig) \
88 ((ig)->read_ptr < (ig)->read_end ? \
89 *((ig)->read_ptr++) : \
90 i_io_getc_imp(ig))
91 #define i_io_peekc(ig) \
92 ((ig)->read_ptr < (ig)->read_end ? \
93 *((ig)->read_ptr) : \
94 i_io_peekc_imp(ig))
95 #define i_io_putc(ig, c) \
96 ((ig)->write_ptr < (ig)->write_end && !(ig)->error ? \
97 *(ig)->write_ptr++ = (c) : \
98 i_io_putc_imp(ig, (c)))
99 #define i_io_eof(ig) \
100 ((ig)->read_ptr == (ig)->read_end && (ig)->buf_eof)
101 #define i_io_error(ig) \
102 ((ig)->read_ptr == (ig)->read_end && (ig)->error)
0778adbf » Tony Cook
2006-03-22 More iolayers work:
103
104 #endif
Something went wrong with that request. Please try again.