[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / tests / linebuf_test.c
blobc3c3b37599b58f014e92347acbc52db0fd36842c
1 #include <stdint.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <gpxe/linebuf.h>
6 static const char data1[] =
7 "Hello world\r\n"
8 "This is a reasonably nice set of lines\n"
9 "with not many different terminators\r\n\r\n"
10 "There should be exactly one blank line above\n"
11 "and this line should never appear at all since it has no terminator";
13 void linebuf_test ( void ) {
14 struct line_buffer linebuf;
15 const char *data = data1;
16 size_t len = ( sizeof ( data1 ) - 1 /* be mean; strip the NUL */ );
17 ssize_t frag_len;
18 char *line;
20 memset ( &linebuf, 0, sizeof ( linebuf ) );
21 while ( len ) {
22 frag_len = line_buffer ( &linebuf, data, len );
23 if ( frag_len < 0 ) {
24 printf ( "line_buffer() failed: %s\n",
25 strerror ( frag_len ) );
26 return;
28 data += frag_len;
29 len -= frag_len;
30 if ( ( line = buffered_line ( &linebuf ) ) )
31 printf ( "\"%s\"\n", line );
34 empty_line_buffer ( &linebuf );