picofuse

io.h
Go to the documentation of this file.
1 
32 #pragma once
33 #include <stdbool.h>
34 #include <stddef.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
45 #ifndef SYS_IOSTREAM_CAPACITY
46 #define SYS_IOSTREAM_CAPACITY 8
47 #endif
48 
54 #define SYS_IOSTREAM_EOF (-1)
55 
57 // TYPES
58 
71 
79 typedef enum sys_iostream_event_t {
87 
96 typedef void (*sys_iostream_callback_t)(sys_iostream_t *stream,
97  sys_iostream_event_t events,
98  void *userdata);
99 
101 // LIFECYCLE
102 
111 extern void sys_iostream_close(sys_iostream_t *s);
112 
114 // METHODS
115 
125 extern int sys_iostream_peek(sys_iostream_t *s);
126 
136 extern size_t sys_iostream_read(sys_iostream_t *s, char *buf, size_t n);
137 
160 extern bool sys_iostream_eof(sys_iostream_t *s);
161 
173 extern size_t sys_iostream_write(sys_iostream_t *s, const char *buf, size_t n);
174 
187 extern ptrdiff_t sys_iostream_seek(sys_iostream_t *s, ptrdiff_t offset,
188  bool abs);
189 
199 extern bool sys_iostream_set_callback(sys_iostream_t *stream,
200  sys_iostream_callback_t callback,
201  void *userdata);
202 
204 
205 #ifdef __cplusplus
206 }
207 #endif
bool sys_iostream_set_callback(sys_iostream_t *stream, sys_iostream_callback_t callback, void *userdata)
Set a callback for stream readiness events.
int sys_iostream_peek(sys_iostream_t *s)
Look at the next byte without consuming it.
Data is available to read.
Definition: io.h:83
size_t sys_iostream_read(sys_iostream_t *s, char *buf, size_t n)
Read bytes from a stream.
struct sys_iostream_t sys_iostream_t
An opaque byte stream.
Definition: io.h:70
void(* sys_iostream_callback_t)(sys_iostream_t *stream, sys_iostream_event_t events, void *userdata)
Callback invoked when a stream becomes ready for I/O.
Definition: io.h:96
ptrdiff_t sys_iostream_seek(sys_iostream_t *s, ptrdiff_t offset, bool abs)
Move a stream&#39;s read/write position.
The stream can accept output.
Definition: io.h:85
size_t sys_iostream_write(sys_iostream_t *s, const char *buf, size_t n)
Write bytes to a stream.
sys_iostream_event_t
Stream readiness event flags.
Definition: io.h:79
No event.
Definition: io.h:81
void sys_iostream_close(sys_iostream_t *s)
Release a stream back to the pool.
bool sys_iostream_eof(sys_iostream_t *s)
Report whether a stream has permanently ended.