1 /* Simple test of putwc in the C locale.
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 static const char outname[] = OBJPFX "tst_putwc.temp";
27 /* Prototype for our test function. */
29 #define TEST_FUNCTION do_test ()
31 /* This defines the `main' function and some more. */
32 #include <test-skeleton.c>
37 const wchar_t str[] = L"This is a test of putwc\n";
43 add_temp_file (outname);
45 fp = fopen (outname, "w+");
47 error (EXIT_FAILURE, errno, "cannot open temporary file");
49 for (n = 0; str[n] != L'\0'; ++n)
52 /* First try reading after rewinding. */
55 wmemset (buf, L'\0', sizeof (buf) / sizeof (buf[0]));
57 while (! feof (fp) && n < sizeof (buf) - 1)
66 if (wcscmp (buf, L"This is a test of putwc\n") != 0)
68 puts ("first comparison failed");
72 /* Now close the file, open it again, and read again. */
75 printf ("failure during fclose: %m\n");
79 fp = fopen (outname, "r");
82 printf ("cannot reopen file: %m\n");
86 /* We can remove the file now. */
89 wmemset (buf, L'\0', sizeof (buf) / sizeof (buf[0]));
91 while (! feof (fp) && n < sizeof (buf) - 1)
100 if (wcscmp (buf, L"This is a test of putwc\n") != 0)
102 puts ("second comparison failed");
106 if (fclose (fp) != 0)
108 printf ("failure during fclose: %m\n");
112 /* Next test: write a bit more than a few bytes. */
113 fp = fopen (outname, "w");
115 error (EXIT_FAILURE, errno, "cannot open temporary file");
117 for (n = 0; n < 4098; ++n)