/* buffer.h : buffer i/o library */ /* * PUBLIC DOMAIN - NO COPYRIGHT CLAIMED - Jonathan Mayo - April 2004 * * Updated: June 2008 * */ #ifndef BUFFER_H #define BUFFER_H #include struct buffer { unsigned max; /* current allocated size */ /* unsigned resize;*/ /* TODO: support realloc up to this size */ unsigned len; /* length of buffer */ char *data; }; /* buffer.c */ void buffer_init(struct buffer *bd, int max); void buffer_free(struct buffer *bd); const char *buffer_read_prepare(struct buffer *bd, size_t *len); void buffer_read_commit(struct buffer *bd, size_t len); size_t buffer_read(struct buffer *bd, size_t len, char *data); char *buffer_write_prepare(struct buffer *bd, size_t req_len); void buffer_write_commit(struct buffer *bd, size_t len, int expand_crlf); size_t buffer_write(struct buffer *bd, size_t len, const char *data, int expand_crlf); size_t buffer_avail(struct buffer *bd); size_t buffer_len(struct buffer *bd); int buffer_read_line(struct buffer *bd, size_t len, char *line); void buffer_readline_begin(struct buffer *b, const char **buf, size_t *bufleft); void buffer_readline_end(struct buffer *b, const char **buf); const char *buffer_readline_next(const char **buf, size_t *bufleft, size_t *linelen); #endif /* vim: ts=4 sts=0 noet sw=4 */