Fix build for hurd/thread-self.c for i386.
[glibc.git] / libio / tst-memstream1.c
blobadc2aec257da51d1e42992378e903df2942eb0b1
1 #include <mcheck.h>
2 #include <stdio.h>
3 #include <stdlib.h>
6 #ifndef CHAR_T
7 # define CHAR_T char
8 # define W(o) o
9 # define OPEN_MEMSTREAM open_memstream
10 #endif
12 #define S(s) S1 (s)
13 #define S1(s) #s
16 static void
17 mcheck_abort (enum mcheck_status ev)
19 printf ("mecheck failed with status %d\n", (int) ev);
20 exit (1);
24 static int
25 do_test (void)
27 mcheck_pedantic (mcheck_abort);
29 CHAR_T *buf = (CHAR_T *) 1l;
30 size_t len = 12345;
31 FILE *fp = OPEN_MEMSTREAM (&buf, &len);
32 if (fp == NULL)
34 printf ("%s failed\n", S(OPEN_MEMSTREAM));
35 return 1;
38 if (fflush (fp) != 0)
40 puts ("fflush failed");
41 return 1;
44 if (len != 0)
46 puts ("string after no write not empty");
47 return 1;
49 if (buf == (CHAR_T *) 1l)
51 puts ("buf not updated");
52 return 1;
54 if (buf[0] != W('\0'))
56 puts ("buf[0] != 0");
57 return 1;
60 buf = (CHAR_T *) 1l;
61 len = 12345;
62 if (fclose (fp) != 0)
64 puts ("fclose failed");
65 return 1;
68 if (len != 0)
70 puts ("string after close with no write not empty");
71 return 1;
73 if (buf == (CHAR_T *) 1l)
75 puts ("buf not updated");
76 return 1;
78 if (buf[0] != W('\0'))
80 puts ("buf[0] != 0");
81 return 1;
84 free (buf);
86 return 0;
89 #define TEST_FUNCTION do_test ()
90 #include "../test-skeleton.c"