X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/902b9f3ff9d45ff4dccc35b1acaa3311865656ad..5f624baebe43889bb2810720cb9cc6d0812f49cb:/lib/sink.h diff --git a/lib/sink.h b/lib/sink.h index d3ab999..fc99d6b 100644 --- a/lib/sink.h +++ b/lib/sink.h @@ -25,6 +25,7 @@ #include struct dynstr; +struct socketio; /** @brief Sink type * @@ -70,6 +71,9 @@ struct sink *sink_discard(void); struct sink *sink_error(void); /* return a sink which fails all writes */ +struct sink *sink_socketio(struct socketio *sio); +/* return a sink which writes to a socket */ + int sink_vprintf(struct sink *s, const char *fmt, va_list ap); int sink_printf(struct sink *s, const char *fmt, ...) attribute((format (printf, 2, 3))); @@ -111,6 +115,29 @@ static inline int sink_err(struct sink *s) { return s->error(s); } +struct source { + int (*getch)(struct source *s); + int (*error)(struct source *s); + int (*eof)(struct source *s); + + enum error_class eclass; +}; + +struct source *source_stdio(FILE *fp); +struct source *source_socketio(struct socketio *sio); + +static inline int source_getc(struct source *s) { + return s->getch(s); +} + +static inline int source_err(struct source *s) { + return s->error(s); +} + +static inline int source_eof(struct source *s) { + return s->eof(s); +} + #endif /* SINK_H */ /*