12#ifndef LOADERS_GP_IO_H
13#define LOADERS_GP_IO_H
18#include <loaders/gp_types.h>
21 ssize_t (*read)(gp_io *self,
void *buf,
size_t size);
22 ssize_t (*write)(gp_io *self,
const void *buf,
size_t size);
24 int (*close)(gp_io *self);
30#define GP_IO_PRIV(io) ((void *)(io)->priv)
35static inline ssize_t gp_io_read(gp_io *io,
void *buf,
size_t size)
37 return io->read(io, buf, size);
40static inline ssize_t gp_io_write(gp_io *io,
const void *buf,
size_t size)
42 return io->write(io, buf, size);
45static inline int gp_io_close(gp_io *io)
50static inline off_t gp_io_seek(gp_io *io, off_t off,
enum gp_seek_whence whence)
52 return io->seek(io, off, whence);
58static inline int gp_io_putc(gp_io *io,
char c)
60 return io->write(io, &c, 1) != 1;
63static inline int gp_io_getb(gp_io *io)
67 if (io->read(io, &c, 1) != 1)
76static inline off_t gp_io_tell(gp_io *io)
78 return io->seek(io, 0, GP_SEEK_CUR);
84static inline off_t gp_io_rewind(gp_io *io)
86 return io->seek(io, 0, GP_SEEK_SET);
89static inline off_t gp_io_peek(gp_io *io,
void *buf,
size_t size)
91 off_t cur_off = gp_io_tell(io);
93 if (gp_io_read(io, buf, size) != (ssize_t)size)
96 return gp_io_seek(io, cur_off, GP_SEEK_SET);
105off_t gp_io_size(gp_io *io);
112int gp_io_fill(gp_io *io,
void *buf,
size_t size);
119int gp_io_flush(gp_io *io,
const void *buf,
size_t size);
124enum gp_io_mark_types {
129int gp_io_mark(gp_io *self,
enum gp_io_mark_types type);
134enum gp_io_fmt_types {
136 GP_IO_CONST = 0x0000,
148 GP_IO_ARRAY = 0x0600,
151 GP_IO_I1 = GP_IO_IGN | 1,
152 GP_IO_I2 = GP_IO_IGN | 2,
153 GP_IO_I3 = GP_IO_IGN | 3,
154 GP_IO_I4 = GP_IO_IGN | 4,
164 GP_IO_PPSTR = 0x0800,
169#define GP_IO_TYPE_MASK 0xff00
171int gp_io_readf(gp_io *self,
const uint16_t *types, ...);
173int gp_io_writef(gp_io *self,
const uint16_t *types, ...);
180int gp_io_printf(gp_io *self,
const char *fmt, ...)
181 __attribute__ ((format (printf, 2, 3)));
186int gp_io_read_b4(gp_io *io, uint32_t *val);
188int gp_io_read_b2(gp_io *io, uint16_t *val);
190enum gp_io_file_mode {
199gp_io *gp_io_file(
const char *path,
enum gp_io_file_mode mode);
206gp_io *gp_io_mem(
void *buf,
size_t size,
void (*free)(
void *));
219gp_io *gp_io_sub_io(gp_io *pio,
size_t size);
226gp_io *gp_io_wbuffer(gp_io *pio,
size_t bsize);
Seek contants and transformations.
gp_seek_whence
Seek constants.