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