math: Remove bogus math implementations
[glibc.git] / libio / tst-bz24051.c
bloba9903f20a303235569dfab1c3bc5f7e68a7356cb
1 /* Test that assigning to stdout redirects puts, putchar, etc (BZ#24051)
2 Copyright (C) 2019-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/>. */
20 /* Prevent putchar -> _IO_putc inline expansion. */
21 #define __NO_INLINE__
22 #pragma GCC optimize("O0")
24 #include <stdio.h>
25 #include <string.h>
26 #include <wchar.h>
28 #include <array_length.h>
29 #include <support/check.h>
30 #include <support/temp_file.h>
31 #include <support/test-driver.h>
33 #undef putchar
34 #undef putwchar
36 static int
37 do_test_narrow (void)
39 char buf[100];
40 int fd = create_temp_file ("tst-bz24051", NULL);
41 stdout = fdopen (fd, "w+");
42 TEST_VERIFY_EXIT (stdout != NULL);
44 printf ("ab%s", "cd");
45 putchar ('e');
46 putchar_unlocked ('f');
47 puts ("ghi");
49 rewind (stdout);
50 TEST_VERIFY_EXIT (fgets (buf, sizeof (buf), stdout) != NULL);
51 TEST_VERIFY (strcmp (buf, "abcdefghi\n") == 0);
53 return 0;
56 static int
57 do_test_wide (void)
59 wchar_t buf[100];
60 int fd = create_temp_file ("tst-bz24051w", NULL);
61 stdout = fdopen (fd, "w+");
62 TEST_VERIFY_EXIT (stdout != NULL);
64 wprintf (L"ab%ls", L"cd");
65 putwchar (L'e');
66 putwchar_unlocked (L'f');
68 rewind (stdout);
69 TEST_VERIFY_EXIT (fgetws (buf, array_length (buf), stdout) != NULL);
70 TEST_VERIFY (wcscmp (buf, L"abcdef") == 0);
72 return 0;
75 static int
76 do_test (void)
78 return do_test_narrow () + do_test_wide ();
81 #include <support/test-driver.c>