[linebuf] Support buffering of multiple lines

Allow line buffer to accumulate multiple lines, with buffered_line()
returning each freshly-completed line as it is encountered.  This
allows buffered lines to be subsequently processed as a group.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2015-07-28 16:59:11 +01:00
parent 20d35b0145
commit 1e4ff872be
4 changed files with 359 additions and 46 deletions

View File

@@ -14,17 +14,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** A line buffer */
struct line_buffer {
/** Current string in the buffer */
/** Data buffer */
char *data;
/** Length of current string, excluding the terminating NUL */
/** Length of buffered data */
size_t len;
/** String is ready to read */
int ready;
/** Most recently consumed length */
size_t consumed;
};
extern char * buffered_line ( struct line_buffer *linebuf );
extern ssize_t line_buffer ( struct line_buffer *linebuf,
const char *data, size_t len );
extern int line_buffer ( struct line_buffer *linebuf,
const char *data, size_t len );
extern void empty_line_buffer ( struct line_buffer *linebuf );
#endif /* _IPXE_LINEBUF_H */