.
[glibc/history.git] / libio / tst-memstream1.c
blobd18f5cc22af8c19ff8cd35ed2fa78af79fd618a0
1 #include <mcheck.h>
2 #include <stdio.h>
5 #ifndef CHAR_T
6 # define CHAR_T char
7 # define W(o) o
8 # define OPEN_MEMSTREAM open_memstream
9 #endif
11 #define S(s) S1 (s)
12 #define S1(s) #s
15 static void
16 mcheck_abort (enum mcheck_status ev)
18 printf ("mecheck failed with status %d\n", (int) ev);
19 exit (1);
23 static int
24 do_test (void)
26 mcheck_pedantic (mcheck_abort);
28 CHAR_T *buf = (CHAR_T *) 1l;
29 size_t len = 12345;
30 FILE *fp = OPEN_MEMSTREAM (&buf, &len);
31 if (fp == NULL)
33 printf ("%s failed\n", S(OPEN_MEMSTREAM));
34 return 1;
37 if (fflush (fp) != 0)
39 puts ("fflush failed");
40 return 1;
43 if (len != 0)
45 puts ("string after no write not empty");
46 return 1;
48 if (buf == (CHAR_T *) 1l)
50 puts ("buf not updated");
51 return 1;
53 if (buf[0] != W('\0'))
55 puts ("buf[0] != 0");
56 return 1;
59 buf = (CHAR_T *) 1l;
60 len = 12345;
61 if (fclose (fp) != 0)
63 puts ("fclose failed");
64 return 1;
67 if (len != 0)
69 puts ("string after close with no write not empty");
70 return 1;
72 if (buf == (CHAR_T *) 1l)
74 puts ("buf not updated");
75 return 1;
77 if (buf[0] != W('\0'))
79 puts ("buf[0] != 0");
80 return 1;
83 free (buf);
85 return 0;
88 #define TEST_FUNCTION do_test ()
89 #include "../test-skeleton.c"