DEADSOFTWARE

files: add abstract streams
[flatwaifu.git] / src / common / streams.c
1 #include "streams.h"
3 #include <stddef.h>
4 #include <stdint.h>
6 #include "misc.h" // endianness conversion
8 void stream_read (void *data, size_t size, size_t n, Reader *r) {
9 r->read(r, data, size, n);
10 }
12 int8_t stream_read8 (Reader *r) {
13 int8_t x;
14 r->read(r, &x, 1, 1);
15 return x;
16 }
18 int16_t stream_read16 (Reader *r) {
19 int16_t x;
20 r->read(r, &x, 2, 1);
21 return short2host(x);
22 }
24 int32_t stream_read32 (Reader *r) {
25 int32_t x;
26 r->read(r, &x, 4, 1);
27 return int2host(x);
28 }
30 void stream_write (const void *data, size_t size, size_t n, Writer *w) {
31 w->write(w, data, size, n);
32 }
34 void stream_write8 (int8_t x, Writer *w) {
35 w->write(w, &x, 1, 1);
36 }
38 void stream_write16 (int16_t x, Writer *w) {
39 int16_t y = short2host(x);
40 w->write(w, &y, 2, 1);
41 }
43 void stream_write32 (int32_t x, Writer *w) {
44 int32_t y = int2host(x);
45 w->write(w, &y, 4, 1);
46 }