linebuf_test.c

Go to the documentation of this file.
00001 #include <stdint.h>
00002 #include <string.h>
00003 #include <stdio.h>
00004 #include <gpxe/linebuf.h>
00005 
00006 static const char data1[] = 
00007 "Hello world\r\n"
00008 "This is a reasonably nice set of lines\n"
00009 "with not many different terminators\r\n\r\n"
00010 "There should be exactly one blank line above\n"
00011 "and this line should never appear at all since it has no terminator";
00012 
00013 void linebuf_test ( void ) {
00014         struct line_buffer linebuf;
00015         const char *data = data1;
00016         size_t len = ( sizeof ( data1 ) - 1 /* be mean; strip the NUL */ );
00017         ssize_t frag_len;
00018         char *line;
00019 
00020         memset ( &linebuf, 0, sizeof ( linebuf ) );
00021         while ( len ) {
00022                 frag_len = line_buffer ( &linebuf, data, len );
00023                 if ( frag_len < 0 ) {
00024                         printf ( "line_buffer() failed: %s\n",
00025                                  strerror ( frag_len ) );
00026                         return;
00027                 }
00028                 data += frag_len;
00029                 len -= frag_len;
00030                 if ( ( line = buffered_line ( &linebuf ) ) )
00031                         printf ( "\"%s\"\n", line );
00032         }
00033 
00034         empty_line_buffer ( &linebuf );
00035 }

Generated on Tue Apr 6 20:01:11 2010 for gPXE by  doxygen 1.5.7.1