1 /* BZ #24024 strerror and errno test.
3 Copyright (C) 2019-2022 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/>. */
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
35 static void *(*real_malloc
) (size_t size
);
38 real_malloc
= dlsym (RTLD_NEXT
, "malloc");
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. */
56 TEST_COMPARE (errno
, 0);
58 locale_t l
= xnewlocale (LC_ALL_MASK
, "C", NULL
);
59 msg
= strerror_l (-3, l
);
61 TEST_COMPARE (errno
, 0);
66 #include <support/test-driver.c>