Added generic line-buffering code (a la stdio)

This commit is contained in:
Michael Brown
2007-01-12 17:08:37 +00:00
parent bcd6ca3291
commit 996b091b50
3 changed files with 200 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#ifndef _GPXE_LINEBUF_H
#define _GPXE_LINEBUF_H
/** @file
*
* Line buffering
*
*/
#include <stdint.h>
#include <stddef.h>
/** A line buffer */
struct line_buffer {
/** Current data in the buffer */
char *data;
/** Length of current data */
size_t len;
/** Bitmask of terminating characters to skip over */
unsigned int skip_terminators;
};
/**
* Retrieve buffered-up line
*
* @v linebuf Line buffer
* @ret line Buffered line, or NULL if no line present
*/
static inline char * buffered_line ( struct line_buffer *linebuf ) {
return linebuf->data;
}
extern int line_buffer ( struct line_buffer *linebuf, const char *data,
size_t len );
extern void empty_line_buffer ( struct line_buffer *linebuf );
#endif /* _GPXE_LINEBUF_H */