commit: 38da99c56d268702d98ec3040bedba351c44aa35
parent 4bf578acbaab8c77b2c137188fd540d2e55ff573
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 24 Aug 2024 00:40:10 +0200
lib/reallocarray.h: new
Diffstat:
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/configure.d/reallocarray.c b/configure.d/reallocarray.c
@@ -2,11 +2,9 @@
// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
// SPDX-License-Identifier: MPL-2.0
-// For reallocarray
-#define _BSD_SOURCE
-#if __NetBSD_Version__ < 1000000000
-#define _OPENBSD_SOURCE
-#endif
+#define _POSIX_C_SOURCE 202405L
+
+#include "../lib/reallocarray.h"
#include <stdlib.h> // reallocarray
diff --git a/lib/reallocarray.h b/lib/reallocarray.h
@@ -0,0 +1,17 @@
+// utils-std: Collection of commonly available Unix tools
+// 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
+
+// pre-POSIX.1-2024 reallocarray fallback
+#if !defined(_POSIX_VERSION) || _POSIX_VERSION < 202405L
+#define _BSD_SOURCE
+#if __NetBSD_Version__ < 1000000000
+#define _OPENBSD_SOURCE
+#endif
+#endif
+
+#include <stdlib.h> // reallocarray
diff --git a/lib/tr_str.c b/lib/tr_str.c
@@ -31,14 +31,11 @@
* SUCH DAMAGE.
*/
-// For reallocarray
-#define _BSD_SOURCE
-#if __NetBSD_Version__ < 1000000000
-#define _OPENBSD_SOURCE
-#endif
-
+#define _POSIX_C_SOURCE 202405L
#include "./tr_str.h"
+#include "./reallocarray.h"
+
#include <assert.h>
#include <ctype.h>
#include <err.h>