1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef WRITER_H
30 #define WRITER_H
31
32 #include "../public/nsapi.h"
33 #include <cx/string.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 typedef ssize_t (*wr_writefunc)(
void *,
const char *,
size_t);
40
41 typedef struct Writer {
42 void *fd;
43 wr_writefunc write;
44 char *buffer;
45 size_t size;
46 size_t pos;
47 int error;
48 } Writer;
49
50 #define writer_put_lit(w, str) writer_put(w, str,
sizeof(str)-
1)
51 #define writer_put_str(w, str) writer_put(w, str, strlen(str))
52
53 void writer_init(Writer *w,
SYS_NETFD fd,
char *buf,
size_t len);
54
55 void writer_init_with_stream(Writer *w,
void *stream, wr_writefunc writefunc,
char *buf,
size_t len);
56
57 int writer_flush(Writer *w);
58
59 int writer_put(Writer *w,
const char *s,
size_t len);
60
61 int writer_puts(Writer *w, cxstring s);
62
63 int writer_putc(Writer *w,
char c);
64
65 int writer_fwrite(
const void *s,
size_t size,
size_t nelem, Writer *w);
66
67 #ifdef __cplusplus
68 }
69 #endif
70
71 #endif
72
73