|
|
1.1 ! root 1: #include <stdint.h> ! 2: #include <string.h> ! 3: #include <stdio.h> ! 4: #include <ipxe/linebuf.h> ! 5: ! 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"; ! 12: ! 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; ! 19: ! 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; ! 27: } ! 28: data += frag_len; ! 29: len -= frag_len; ! 30: if ( ( line = buffered_line ( &linebuf ) ) ) ! 31: printf ( "\"%s\"\n", line ); ! 32: } ! 33: ! 34: empty_line_buffer ( &linebuf ); ! 35: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.