file tst-aio10.c was initially added on branch fedora-branch.
[glibc/history.git] / libio / bug-wmemstream1.c
blob2190593c9332997b16cbabc7a4f5914820ca9969
1 #include <stdio.h>
2 #include <string.h>
5 static int
6 do_test (void)
8 size_t size;
9 wchar_t *buf;
10 FILE *fp = open_wmemstream (&buf, &size);
11 if (fp == NULL)
13 puts ("open_wmemstream failed");
14 return 1;
17 off64_t off = ftello64 (fp);
18 if (off != 0)
20 puts ("initial position wrong");
21 return 1;
24 if (fseek (fp, 32768, SEEK_SET) != 0)
26 puts ("fseek failed");
27 return 1;
30 if (fputws (L"foo", fp) == EOF)
32 puts ("fputws failed");
33 return 1;
36 if (fclose (fp) == EOF)
38 puts ("fclose failed");
39 return 1;
42 if (size != 32768 + 3)
44 printf ("expected size %d, got %zu\n", 32768 + 3, size);
45 return 1;
48 for (int i = 0; i < 32768; ++i)
49 if (buf[i] != L'\0')
51 printf ("wide character at offset %d is %#x\n",
52 i, (unsigned int) buf[i]);
53 return 1;
56 if (wmemcmp (buf + 32768, L"foo", 3) != 0)
58 puts ("written string incorrect");
59 return 1;
62 /* Mark the buffer. */
63 wmemset (buf, L'A', size);
64 free (buf);
66 /* Try again, this time with write mode enabled before the seek. */
67 fp = open_wmemstream (&buf, &size);
68 if (fp == NULL)
70 puts ("2nd open_wmemstream failed");
71 return 1;
74 off = ftello64 (fp);
75 if (off != 0)
77 puts ("2nd initial position wrong");
78 return 1;
81 if (fputws (L"bar", fp) == EOF)
83 puts ("2nd fputws failed");
84 return 1;
87 if (fseek (fp, 32768, SEEK_SET) != 0)
89 puts ("2nd fseek failed");
90 return 1;
93 if (fputws (L"foo", fp) == EOF)
95 puts ("3rd fputws failed");
96 return 1;
99 if (fclose (fp) == EOF)
101 puts ("2nd fclose failed");
102 return 1;
105 if (size != 32768 + 3)
107 printf ("2nd expected size %d, got %zu\n", 32768 + 3, size);
108 return 1;
111 if (wmemcmp (buf, L"bar", 3) != 0)
113 puts ("initial string incorrect in 2nd try");
114 return 1;
117 for (int i = 3; i < 32768; ++i)
118 if (buf[i] != L'\0')
120 printf ("wide character at offset %d is %#x in 2nd try\n",
121 i, (unsigned int) buf[i]);
122 return 1;
125 if (wmemcmp (buf + 32768, L"foo", 3) != 0)
127 puts ("written string incorrect in 2nd try");
128 return 1;
131 return 0;
134 #define TEST_FUNCTION do_test ()
135 #include "../test-skeleton.c"