test-buffer.c 658 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <zebra.h>
  2. #include <memory.h>
  3. #include <buffer.h>
  4. struct thread_master *master;
  5. int
  6. main(int argc, char **argv)
  7. {
  8. struct buffer *b1, *b2;
  9. int n;
  10. char junk[3];
  11. char c = 'a';
  12. memory_init();
  13. if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1))
  14. {
  15. fprintf(stderr, "Usage: %s <number of chars to simulate>\n", *argv);
  16. return 1;
  17. }
  18. b1 = buffer_new(0);
  19. b2 = buffer_new(1024);
  20. while (n-- > 0)
  21. {
  22. buffer_put(b1, &c, 1);
  23. buffer_put(b2, &c, 1);
  24. if (c++ == 'z')
  25. c = 'a';
  26. buffer_reset(b1);
  27. buffer_reset(b2);
  28. }
  29. buffer_free(b1);
  30. buffer_free(b2);
  31. return 0;
  32. }