include/string.h: Also redirect calls if not inlined in libpthread
[glibc.git] / libio / test-fputs-unbuffered-full.c
blobd30196964149d39ebd7a7c36d2cd3f2297292192
1 /* Regression test for 20632.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <support/check.h>
24 #include <support/xunistd.h>
25 #include <unistd.h>
27 #ifndef WIDE
28 # define TEST_NAME "fputs-unbuffered-full"
29 # define CHAR char
30 # define FPUTS fputs
31 # define TEXT "0123456789ABCDEF"
32 #else
33 # include <wchar.h>
34 # define TEST_NAME "fputws-unbuffered-full"
35 # define CHAR wchar_t
36 # define FPUTS fputws
37 # define TEXT L"0123456789ABCDEF"
38 #endif /* WIDE */
41 static int
42 do_test (void)
44 /* Open an unbuffered stream to /dev/full. */
45 FILE *fp = fopen ("/dev/full", "w");
46 TEST_VERIFY_EXIT (fp != NULL);
47 int ret = setvbuf (fp, NULL, _IONBF, 0);
48 TEST_VERIFY_EXIT (ret == 0);
50 /* Output a long string. */
51 const int sz = 4096;
52 CHAR *buff = calloc (sz+1, sizeof *buff);
53 for (int i=0; i < sz; i++)
54 buff[i] = (CHAR) 'x';
55 buff[sz] = (CHAR) '\0';
56 errno = 0;
57 ret = FPUTS (buff, fp);
58 TEST_VERIFY (ret == EOF);
59 TEST_VERIFY (errno == ENOSPC);
60 free (buff);
62 /* Output shorter strings. */
63 for (int i=0; i < 1024; i++)
65 errno = 0;
66 ret = FPUTS (TEXT, fp);
67 TEST_VERIFY (ret == EOF);
68 TEST_VERIFY (errno == ENOSPC);
70 /* Call malloc, triggering a crash if its
71 function pointers have been overwritten. */
72 void *volatile ptr = malloc (1);
73 free (ptr);
75 return 0;
78 #include <support/test-driver.c>