1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
4 | |
5 | int |
6 | main (void) |
7 | { |
8 | char *bp; |
9 | size_t size; |
10 | FILE *stream; |
11 | int lose = 0; |
12 | |
13 | stream = open_memstream (bufloc: &bp, sizeloc: &size); |
14 | fprintf (stream, "hello" ); |
15 | fflush (stream); |
16 | printf (format: "buf = %s, size = %Zu\n" , bp, size); |
17 | lose |= size != 5; |
18 | lose |= strncmp (bp, "hello" , size); |
19 | fprintf (stream, ", world" ); |
20 | fclose (stream); |
21 | printf (format: "buf = %s, size = %Zu\n" , bp, size); |
22 | lose |= size != 12; |
23 | lose |= strncmp (bp, "hello, world" , 12); |
24 | |
25 | puts (s: lose ? "Test FAILED!" : "Test succeeded." ); |
26 | |
27 | free (ptr: bp); |
28 | |
29 | return lose; |
30 | } |
31 | |