posix: Check pidfd_spawn with tst-spawn7-pid
[glibc.git] / string / test-strerror-errno.c
blob606ee4ecbbb890cecaae703b0b3da295252a1259
1 /* BZ #24024 strerror and errno test.
3 Copyright (C) 2019-2023 Free Software Foundation, Inc.
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 <dlfcn.h>
21 #include <errno.h>
22 #include <string.h>
24 #include <support/check.h>
25 #include <support/support.h>
27 /* malloc is allowed to change errno to a value different than 0, even when
28 there is no actual error. This happens for example when the memory
29 allocation through sbrk fails. Simulate this by interposing our own
30 malloc implementation which sets errno to ENOMEM and calls the original
31 malloc. */
32 void
33 *malloc (size_t size)
35 static void *(*real_malloc) (size_t size);
37 if (!real_malloc)
38 real_malloc = dlsym (RTLD_NEXT, "malloc");
40 errno = ENOMEM;
42 return (*real_malloc) (size);
45 /* strerror must not change the value of errno. Unfortunately due to GCC bug
46 #88576, this happens when -fmath-errno is used. This simple test checks
47 that it doesn't happen. */
48 static int
49 do_test (void)
51 char *msg;
53 errno = 0;
54 msg = strerror (-3);
55 (void) msg;
56 TEST_COMPARE (errno, 0);
58 locale_t l = xnewlocale (LC_ALL_MASK, "C", NULL);
59 msg = strerror_l (-3, l);
60 (void) msg;
61 TEST_COMPARE (errno, 0);
63 return 0;
66 #include <support/test-driver.c>