Use strcasecmp_l instead of strcasecmp
[glibc.git] / libio / tst-memstream2.c
blob9619d7725db2f123f946e79a11651549b67a2f0d
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 for (int outer = 0; outer < 800; ++outer)
39 for (int inner = 0; inner < 100; ++inner)
40 if (fputc (W('a') + (outer * 100 + inner) % 26, fp) == EOF)
42 printf ("fputc at %d:%d failed\n", outer, inner);
43 return 1;
46 if (fflush (fp) != 0)
48 puts ("fflush failed");
49 return 1;
52 if (len != (outer + 1) * 100)
54 printf ("string in round %d not %d bytest long\n",
55 outer + 1, (outer + 1) * 100);
56 return 1;
58 if (buf == (CHAR_T *) 1l)
60 printf ("round %d: buf not updated\n", outer + 1);
61 return 1;
63 for (int inner = 0; inner < (outer + 1) * 100; ++inner)
64 if (buf[inner] != W('a') + inner % 26)
66 printf ("round %d: buf[%d] != '%c'\n", outer + 1, inner,
67 (char) (W('a') + inner % 26));
68 return 1;
72 buf = (CHAR_T *) 1l;
73 len = 12345;
74 if (fclose (fp) != 0)
76 puts ("fclose failed");
77 return 1;
80 if (len != 800 * 100)
82 puts ("string after close not 80000 bytes long");
83 return 1;
85 if (buf == (CHAR_T *) 1l)
87 puts ("buf not updated");
88 return 1;
90 for (int inner = 0; inner < 800 * 100; ++inner)
91 if (buf[inner] != W('a') + inner % 26)
93 printf ("after close: buf[%d] != %c\n", inner,
94 (char) (W('a') + inner % 26));
95 return 1;
98 free (buf);
100 return 0;
103 #define TEST_FUNCTION do_test ()
104 #include "../test-skeleton.c"