1 /* Check that strerror, strerror_l do not return NULL on failure (bug 30555).
2 Copyright (C) 2023-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/>. */
24 #include <support/check.h>
25 #include <support/namespace.h>
26 #include <support/xdlfcn.h>
28 /* Interposed malloc that can be used to inject allocation failures. */
30 static volatile bool fail_malloc
;
38 static void *(*original_malloc
) (size_t);
39 if (original_malloc
== NULL
)
40 original_malloc
= xdlsym (RTLD_NEXT
, "malloc");
41 return original_malloc (size
);
44 /* Callbacks for the actual tests. Use fork to run both tests with a
48 test_strerror (void *closure
)
51 const char *s
= strerror (999);
53 TEST_COMPARE_STRING (s
, "Unknown error");
57 test_strerror_l (void *closure
)
59 locale_t loc
= newlocale (LC_ALL
, "C", (locale_t
) 0);
60 TEST_VERIFY (loc
!= (locale_t
) 0);
62 const char *s
= strerror_l (999, loc
);
64 TEST_COMPARE_STRING (s
, "Unknown error");
71 support_isolate_in_subprocess (test_strerror
, NULL
);
72 support_isolate_in_subprocess (test_strerror_l
, NULL
);
77 #include <support/test-driver.c>