#ifndef WRITER_H
#define WRITER_H
#include "../public/nsapi.h"
#include <cx/string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef ssize_t (*wr_writefunc)(
void *,
const char *,
size_t);
typedef struct Writer {
void *fd;
wr_writefunc write;
char *buffer;
size_t size;
size_t pos;
int error;
} Writer;
#define writer_put_lit(w, str) writer_put(w, str,
sizeof(str)-
1)
#define writer_put_str(w, str) writer_put(w, str, strlen(str))
void writer_init(Writer *w,
SYS_NETFD fd,
char *buf,
size_t len);
void writer_init_with_stream(Writer *w,
void *stream, wr_writefunc writefunc,
char *buf,
size_t len);
int writer_flush(Writer *w);
int writer_put(Writer *w,
const char *s,
size_t len);
int writer_puts(Writer *w, cxstring s);
int writer_putc(Writer *w,
char c);
int writer_fwrite(
const void *s,
size_t size,
size_t nelem, Writer *w);
#ifdef __cplusplus
}
#endif
#endif