![]() |
GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
I/O abstraction for gfxprim loaders. More...
#include <stdint.h>
#include <sys/types.h>
#include <core/gp_compiler.h>
#include <utils/gp_seek.h>
#include <loaders/gp_types.h>
Go to the source code of this file.
Data Structures | |
struct | gp_io |
An I/O abstraction. More... | |
Enumerations | |
enum | gp_io_mark_op { GP_IO_MARK , GP_IO_REWIND } |
Mark operation. More... | |
enum | gp_io_file_mode { GP_IO_RDONLY = 0x00 , GP_IO_WRONLY = 0x01 , GP_IO_RDWR = 0x02 } |
A file mode for gp_io_file(). More... | |
Functions | |
static ssize_t | gp_io_read (gp_io *self, void *buf, size_t size) |
A wrapper for gp_io::read(). | |
static ssize_t | gp_io_write (gp_io *self, const void *buf, size_t size) |
A wrapper for gp_io::write(). | |
static off_t | gp_io_seek (gp_io *self, off_t off, enum gp_seek_whence whence) |
A wrapper for gp_io::seek(). | |
static int | gp_io_close (gp_io *self) |
A wrapper for gp_io::close(). | |
static int | gp_io_putb (gp_io *self, char b) |
A wrapper around gp_io::write() for a single byte. | |
static int | gp_io_getb (gp_io *self) |
A wrapper around gp_io::read() for a single byte. | |
static off_t | gp_io_tell (gp_io *self) |
Returns current offset. | |
static off_t | gp_io_rewind (gp_io *self) |
Rewinds to start of the I/O stream. | |
static off_t | gp_io_peek (gp_io *self, void *buf, size_t size) |
Reads bytes but does not remove then from I/O. | |
off_t | gp_io_size (gp_io *self) |
Returns I/O stream size. | |
int | gp_io_fill (gp_io *self, void *buf, size_t size) |
Fills whole buffer or returns error. | |
int | gp_io_flush (gp_io *self, const void *buf, size_t size) |
Writes whole buffer or retuns error. | |
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. | |
int | gp_io_printf (gp_io *self, const char *fmt,...) |
Printf like function. | |
gp_io * | gp_io_file (const char *path, enum gp_io_file_mode mode) |
Creates I/O from a file. | |
gp_io * | gp_io_mem (void *buf, size_t size, void(*free)(void *)) |
Creates a readable I/O from a memory buffer. | |
gp_io * | gp_io_sub_io (gp_io *self, size_t size) |
Create a read-only sub I/O from a readable I/O. | |
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. | |
I/O abstraction for gfxprim loaders.
Definition in file gp_io.h.
enum gp_io_file_mode |
A file mode for gp_io_file().
Enumerator | |
---|---|
GP_IO_RDONLY | Opens file read only. |
GP_IO_WRONLY | Opens file write only and truncates it if it exists. |
GP_IO_RDWR | Opens a file read/write. |
enum gp_io_mark_op |
|
inlinestatic |
A wrapper for gp_io::close().
Finalizes writes, frees memory.
self | An I/O. |
Definition at line 125 of file gp_io.h.
References gp_io::close.
gp_io * gp_io_file | ( | const char * | path, |
enum gp_io_file_mode | mode ) |
Creates I/O from a file.
The I/O is not buffered, calls to gp_io_read() and gp_io_write() are directly translated into read() and write() calls.
path | A filesystem path. |
mode | Open the I/O read-only, write-only or read-write. Write-only I/O files are truncated. |
int gp_io_fill | ( | gp_io * | self, |
void * | buf, | ||
size_t | size ) |
Fills whole buffer or returns error.
This is a gp_io_read() call with retries that attempts to fill the buffer as long as the underlying read returns any data. It will fail for example if we request more data than there is in a file.
self | An I/O. |
buf | A buffer to read to. |
size | A size of the buffer. |
int gp_io_flush | ( | gp_io * | self, |
const void * | buf, | ||
size_t | size ) |
Writes whole buffer or retuns error.
This is a gp_io_write() call with retries that attempts to write whole buffer as long as the underlying write writes any data. It will fail for example if we attempt to write any data into a file on a full filesystem.
self | An I/O. |
buf | A buffer to write to. |
size | A size of the buffer. |
|
inlinestatic |
A wrapper around gp_io::read() for a single byte.
self | An I/O. |
Definition at line 149 of file gp_io.h.
References gp_io::read.
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.
Only one mark can be placed on an I/O, subsequent calls to gp_io_mark() with GP_IO_MARK rewrite previous mark.
self | An I/O. |
op | An operation either GP_IO_MARK or GP_IO_REWIND. |
gp_io * gp_io_mem | ( | void * | buf, |
size_t | size, | ||
void(* | free )(void *) ) |
Creates a readable I/O from a memory buffer.
buf | A buffer with data. |
size | A size of the data buffer. |
free | A callback that is called with the buf pointer as a parameter on gp_io_close(). If no callback is needed NULL should be passed. |
|
inlinestatic |
Reads bytes but does not remove then from I/O.
self | An I/O. |
buf | A buffer to read to. |
size | A size of the buffer. |
//TODO: fix up the semantics
Definition at line 194 of file gp_io.h.
References gp_io_read(), gp_io_seek(), and gp_io_tell().
int gp_io_printf | ( | gp_io * | self, |
const char * | fmt, | ||
... ) |
Printf like function.
self | An I/O. |
fmt | A printf()-like format. |
... | A printf()-like parameters. |
|
inlinestatic |
A wrapper around gp_io::write() for a single byte.
self | An I/O. |
b | A byte to write into the I/O. |
Definition at line 138 of file gp_io.h.
References gp_io::write.
|
inlinestatic |
A wrapper for gp_io::read().
self | An I/O. |
buf | A buffer to read to. |
size | A size of the buffer. |
Definition at line 83 of file gp_io.h.
References gp_io::read.
Referenced by gp_io_peek().
|
inlinestatic |
Rewinds to start of the I/O stream.
self | An I/O. |
Definition at line 178 of file gp_io.h.
References gp_io::seek.
|
inlinestatic |
A wrapper for gp_io::seek().
self | An I/O. |
off | An offset in the file. |
whence | Defines to what the offset is relative to. |
Definition at line 111 of file gp_io.h.
References gp_io::seek.
Referenced by gp_io_peek().
off_t gp_io_size | ( | gp_io * | self | ) |
Returns I/O stream size.
self | An I/O. |
Create a read-only sub I/O from a readable I/O.
The sub I/O starts at current offset in the parent I/O (which is also point where gp_io_tell() for the new I/O will return zero) and continues for up to size bytes in the parent I/O.
WARNING: If you combine reading/writing in the Sub I/O and parent I/O the result is undefined.
self | A parent I/O. |
size | A size limit of the sub I/O. |
|
inlinestatic |
Returns current offset.
self | An I/O. |
Definition at line 166 of file gp_io.h.
References gp_io::seek.
Referenced by gp_io_peek().
Creates a writeable buffered I/O on the top of the existing I/O.
self | A writeable I/O. |
bsize | A buffer size. Passing zero as bsize select default buffer size. |
|
inlinestatic |
A wrapper for gp_io::write().
self | An I/O. |
buf | A buffer to write to. |
size | A size of the buffer. |
Definition at line 97 of file gp_io.h.
References gp_io::write.