hurd: avoid PLT ref between sendfile and sendfile64
[glibc.git] / libio / tst-memstream2.c
blobd3874faaad7c3b1a3993fb2d65ca7847aa586653
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 for (int outer = 0; outer < 800; ++outer)
40 for (int inner = 0; inner < 100; ++inner)
41 if (fputc (W('a') + (outer * 100 + inner) % 26, fp) == EOF)
43 printf ("fputc at %d:%d failed\n", outer, inner);
44 return 1;
47 if (fflush (fp) != 0)
49 puts ("fflush failed");
50 return 1;
53 if (len != (outer + 1) * 100)
55 printf ("string in round %d not %d bytest long\n",
56 outer + 1, (outer + 1) * 100);
57 return 1;
59 if (buf == (CHAR_T *) 1l)
61 printf ("round %d: buf not updated\n", outer + 1);
62 return 1;
64 for (int inner = 0; inner < (outer + 1) * 100; ++inner)
65 if (buf[inner] != W('a') + inner % 26)
67 printf ("round %d: buf[%d] != '%c'\n", outer + 1, inner,
68 (char) (W('a') + inner % 26));
69 return 1;
73 buf = (CHAR_T *) 1l;
74 len = 12345;
75 if (fclose (fp) != 0)
77 puts ("fclose failed");
78 return 1;
81 if (len != 800 * 100)
83 puts ("string after close not 80000 bytes long");
84 return 1;
86 if (buf == (CHAR_T *) 1l)
88 puts ("buf not updated");
89 return 1;
91 for (int inner = 0; inner < 800 * 100; ++inner)
92 if (buf[inner] != W('a') + inner % 26)
94 printf ("after close: buf[%d] != %c\n", inner,
95 (char) (W('a') + inner % 26));
96 return 1;
99 free (buf);
101 return 0;
104 #define TIMEOUT 100
105 #define TEST_FUNCTION do_test ()
106 #include "../test-skeleton.c"