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. */
22 #pragma GCC optimize("O0")
28 #include <array_length.h>
29 #include <support/check.h>
30 #include <support/temp_file.h>
31 #include <support/test-driver.h>
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");
46 putchar_unlocked ('f');
50 TEST_VERIFY_EXIT (fgets (buf
, sizeof (buf
), stdout
) != NULL
);
51 TEST_VERIFY (strcmp (buf
, "abcdefghi\n") == 0);
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");
66 putwchar_unlocked (L
'f');
69 TEST_VERIFY_EXIT (fgetws (buf
, array_length (buf
), stdout
) != NULL
);
70 TEST_VERIFY (wcscmp (buf
, L
"abcdef") == 0);
78 return do_test_narrow () + do_test_wide ();
81 #include <support/test-driver.c>