test-stream.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <zebra.h>
  2. #include <stream.h>
  3. #include <thread.h>
  4. static long int ham = 0xdeadbeefdeadbeef;
  5. struct thread_master *master;
  6. static void
  7. print_stream (struct stream *s)
  8. {
  9. size_t getp = stream_get_getp (s);
  10. printf ("endp: %ld, readable: %ld, writeable: %ld\n",
  11. stream_get_endp (s),
  12. STREAM_READABLE (s),
  13. STREAM_WRITEABLE (s));
  14. while (STREAM_READABLE (s))
  15. {
  16. printf ("0x%x ", *stream_pnt (s));
  17. stream_forward_getp (s, 1);
  18. }
  19. printf ("\n");
  20. /* put getp back to where it was */
  21. stream_set_getp (s, getp);
  22. }
  23. int
  24. main (void)
  25. {
  26. struct stream *s;
  27. s = stream_new (1024);
  28. stream_putc (s, ham);
  29. stream_putw (s, ham);
  30. stream_putl (s, ham);
  31. stream_putq (s, ham);
  32. print_stream (s);
  33. stream_resize (s, stream_get_endp (s));
  34. print_stream (s);
  35. printf ("c: 0x%hhx\n", stream_getc (s));
  36. printf ("w: 0x%hx\n", stream_getw (s));
  37. printf ("l: 0x%x\n", stream_getl (s));
  38. printf ("q: 0x%lx\n", stream_getq (s));
  39. return 0;
  40. }