announce-gen: add comments
[gnulib.git] / tests / test-calloc-posix.c
blob702c7b6aad15b10120746cd7a82506167e0f679c
1 /* Test of calloc function.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <stdlib.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdint.h>
26 #include "macros.h"
28 /* Work around clang bug
29 <https://github.com/llvm/llvm-project/issues/114772>. */
30 void *(*volatile my_calloc) (size_t, size_t) = calloc;
31 #undef calloc
32 #define calloc my_calloc
34 int
35 main ()
37 /* Check that calloc sets errno when it fails.
38 Do this only in 64-bit processes, because there are many bi-arch systems
39 nowadays where a 32-bit process can actually allocate 2 GiB of RAM. */
40 if (sizeof (size_t) >= 8)
42 void *p;
44 errno = 0;
45 p = calloc (SIZE_MAX / 20, 2);
46 ASSERT (p == NULL);
47 ASSERT (errno == ENOMEM);
49 errno = 0;
50 p = calloc (SIZE_MAX / 6, 2);
51 ASSERT (p == NULL);
52 ASSERT (errno == ENOMEM);
54 return test_exit_status;
56 else
58 fputs ("Skipping test: size_t is not 64-bits wide\n", stderr);
59 return 77;