logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 308373d85a19d073abc58798e979c10ab83448d7
parent 5bdd8f6b17ed618f1302c385e89038a98bac1ea3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 12 Feb 2026 16:15:11 +0100

libutils/reallocarray: relax feature_test_macros requirements

BSD_VISIBLE strikes again

Diffstat:

Mcmd/cut.c1-
Mcmd/df.c1-
Mcmd/join.c1-
Mlib/tr_str.c1-
Mlibutils/reallocarray.c8+++++++-
Mlibutils/reallocarray.h14++++----------
6 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/cmd/cut.c b/cmd/cut.c @@ -3,7 +3,6 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 202405L -#define _BSD_SOURCE // pre-POSIX.1-2024 reallocarray #include "../config.h" #include "../libutils/getopt_nolong.h" diff --git a/cmd/df.c b/cmd/df.c @@ -4,7 +4,6 @@ #define _POSIX_C_SOURCE 202405L #define _DEFAULT_SOURCE // mntent in glibc 2.19+ -#define _BSD_SOURCE // pre-POSIX.1-2024 reallocarray #include "../config.h" #include "../libutils/getopt_nolong.h" diff --git a/cmd/join.c b/cmd/join.c @@ -33,7 +33,6 @@ * SUCH DAMAGE. */ -#define _POSIX_C_SOURCE 202405L #define _BSD_SOURCE // fgetln, strsep #include "../libutils/err.h" diff --git a/lib/tr_str.c b/lib/tr_str.c @@ -32,7 +32,6 @@ */ #define _POSIX_C_SOURCE 202405L -#define _BSD_SOURCE // pre-POSIX.1-2024 reallocarray #include "./tr_str.h" diff --git a/libutils/reallocarray.c b/libutils/reallocarray.c @@ -1,7 +1,6 @@ // Copied from musl // Copyright © 2020 Ariadne Conill <ariadne@dereferenced.org> // SPDX-License-Identifier: MIT -#ifndef HAS_REALLOCARRAY #define _POSIX_C_SOURCE 202405L #define _BSD_SOURCE @@ -10,6 +9,13 @@ #include <errno.h> #include <stdlib.h> +#ifdef HAS_REALLOCARRAY +void * +utils_reallocarray(void *ptr, size_t m, size_t n) +{ + return reallocarray(ptr, m, n); +} +#else /* HAS_REALLOCARRAY */ void * utils_reallocarray(void *ptr, size_t m, size_t n) { diff --git a/libutils/reallocarray.h b/libutils/reallocarray.h @@ -2,18 +2,12 @@ // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> // SPDX-License-Identifier: 0BSD -#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 202405L -#error reallocarray needs: define _POSIX_C_SOURCE 202405L -#endif - -#if !defined(_BSD_SOURCE) -#error reallocarray needs: define _BSD_SOURCE +#ifndef _BSD_SOURCE +# if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 202405L +# error reallocarray needs: define _POSIX_C_SOURCE 202405L or define _BSD_SOURCE +# endif #endif #include <stdlib.h> // reallocarray -#ifdef HAS_REALLOCARRAY -#define utils_reallocarray reallocarray -#else void *utils_reallocarray(void *ptr, size_t m, size_t n); -#endif