11#ifndef LOADERS_GP_IO_H
12#define LOADERS_GP_IO_H
18#include <loaders/gp_types.h>
33 ssize_t (*
read)(
gp_io *self,
void *buf,
size_t size);
43 ssize_t (*
write)(
gp_io *self,
const void *buf,
size_t size);
72#define GP_IO_PRIV(io) ((void *)(io)->priv)
85 return self->
read(self, buf, size);
99 return self->
write(self, buf, size);
113 return self->
seek(self, off, whence);
127 return self->
close(self);
140 return self->
write(self, &b, 1) != 1;
153 if (self->
read(self, &c, 1) != 1)
168 return self->
seek(self, 0, GP_SEEK_CUR);
180 return self->
seek(self, 0, GP_SEEK_SET);
198 if (
gp_io_read(self, buf, size) != (ssize_t)size)
201 return gp_io_seek(self, cur_off, GP_SEEK_SET);
A compiler dependent macros.
#define GP_FMT_PRINTF(fmt, list)
Expands to format printf attribute when supported by the compiler.
gp_io * gp_io_file(const char *path, enum gp_io_file_mode mode)
Creates I/O from a file.
static int gp_io_getb(gp_io *self)
A wrapper around gp_io::read() for a single byte.
off_t gp_io_size(gp_io *self)
Returns I/O stream size.
int gp_io_flush(gp_io *self, const void *buf, size_t size)
Writes whole buffer or retuns error.
static off_t gp_io_peek(gp_io *self, void *buf, size_t size)
Reads bytes but does not remove then from I/O.
static off_t gp_io_rewind(gp_io *self)
Rewinds to start of the I/O stream.
gp_io_file_mode
A file mode for gp_io_file().
@ GP_IO_WRONLY
Opens file write only and truncates it if it exists.
@ GP_IO_RDWR
Opens a file read/write.
@ GP_IO_RDONLY
Opens file read only.
static off_t gp_io_seek(gp_io *self, off_t off, enum gp_seek_whence whence)
A wrapper for gp_io::seek().
int gp_io_mark(gp_io *self, enum gp_io_mark_op op)
Marks a current position or returns to mark in I/O stream.
gp_io * gp_io_wbuffer(gp_io *self, size_t bsize)
Creates a writeable buffered I/O on the top of the existing I/O.
gp_io * gp_io_mem(void *buf, size_t size, void(*free)(void *))
Creates a readable I/O from a memory buffer.
static off_t gp_io_tell(gp_io *self)
Returns current offset.
gp_io_mark_op
Mark operation.
@ GP_IO_REWIND
Rewinds the I/O to a mark.
@ GP_IO_MARK
Puts a mark into an I/O.
static ssize_t gp_io_write(gp_io *self, const void *buf, size_t size)
A wrapper for gp_io::write().
static int gp_io_putb(gp_io *self, char b)
A wrapper around gp_io::write() for a single byte.
int gp_io_printf(gp_io *self, const char *fmt,...)
Printf like function.
static ssize_t gp_io_read(gp_io *self, void *buf, size_t size)
A wrapper for gp_io::read().
static int gp_io_close(gp_io *self)
A wrapper for gp_io::close().
gp_io * gp_io_sub_io(gp_io *self, size_t size)
Create a read-only sub I/O from a readable I/O.
int gp_io_fill(gp_io *self, void *buf, size_t size)
Fills whole buffer or returns error.
Seek contants and transformations.
gp_seek_whence
Seek constants.
ssize_t(* write)(gp_io *self, const void *buf, size_t size)
A write() callback.
off_t mark
A mark to store offset to by the gp_io_mark().
int(* close)(gp_io *self)
A close() callback.
off_t(* seek)(gp_io *self, off_t off, enum gp_seek_whence whence)
A seek() callback.
ssize_t(* read)(gp_io *self, void *buf, size_t size)
A read() callback.