Setup LOCPATH for tst-ftell-active-handler and tst-ftell-partial-wide in libio
[platform/upstream/glibc.git] / libio / tst-memstream1.c
1 #include <mcheck.h>
2 #include <stdio.h>
3
4
5 #ifndef CHAR_T
6 # define CHAR_T char
7 # define W(o) o
8 # define OPEN_MEMSTREAM open_memstream
9 #endif
10
11 #define S(s) S1 (s)
12 #define S1(s) #s
13
14
15 static void
16 mcheck_abort (enum mcheck_status ev)
17 {
18   printf ("mecheck failed with status %d\n", (int) ev);
19   exit (1);
20 }
21
22
23 static int
24 do_test (void)
25 {
26   mcheck_pedantic (mcheck_abort);
27
28   CHAR_T *buf = (CHAR_T *) 1l;
29   size_t len = 12345;
30   FILE *fp = OPEN_MEMSTREAM (&buf, &len);
31   if (fp == NULL)
32     {
33       printf ("%s failed\n", S(OPEN_MEMSTREAM));
34       return 1;
35     }
36
37   if (fflush (fp) != 0)
38     {
39       puts ("fflush failed");
40       return 1;
41     }
42
43   if (len != 0)
44     {
45       puts ("string after no write not empty");
46       return 1;
47     }
48   if (buf == (CHAR_T *) 1l)
49     {
50       puts ("buf not updated");
51       return 1;
52     }
53   if (buf[0] != W('\0'))
54     {
55       puts ("buf[0] != 0");
56       return 1;
57     }
58
59   buf = (CHAR_T *) 1l;
60   len = 12345;
61   if (fclose (fp) != 0)
62     {
63       puts ("fclose failed");
64       return 1;
65     }
66
67   if (len != 0)
68     {
69       puts ("string after close with no write not empty");
70       return 1;
71     }
72   if (buf == (CHAR_T *) 1l)
73     {
74       puts ("buf not updated");
75       return 1;
76     }
77   if (buf[0] != W('\0'))
78     {
79       puts ("buf[0] != 0");
80       return 1;
81     }
82
83   free (buf);
84
85   return 0;
86 }
87
88 #define TEST_FUNCTION do_test ()
89 #include "../test-skeleton.c"