You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

linebuf_test.c 910B

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