A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
+subprojects/reallocarray-musl/
M meson.build => meson.build +2 -1
@@ 44,4 44,5 @@ if has_advisory_info
assert(cc.has_function('posix_madvise', dependencies: [rt], prefix: '#define _POSIX_C_SOURCE 200809L'), 'posix_madvise() missing')
endif
-which = executable('which', 'which.c', dependencies: [pthread, rt], install: true)
+reallocarray = subproject('reallocarray-musl').get_variable('reallocarray_musl_dep')
+which = executable('which', 'which.c', dependencies: [pthread, rt, reallocarray], install: true)
A subprojects/packagefiles/reallocarray-musl.patch => subprojects/packagefiles/reallocarray-musl.patch +15 -0
@@ 0,0 1,15 @@
+diff -u0 -r -N musl/meson.build musl2/meson.build
+--- musl/meson.build
++++ musl2/meson.build
+@@ -0,0 +1,6 @@
++# SPDX-FileCopyrightText: 2023 John Scott <jscott@posteo.net>
++# SPDX-License-Identifier: GPL-3.0-or-later
++# Note that musl is under a different medley of licenses.
++# The above license and copyright information is only for this file itself.
++project('reallocarray_musl', 'c')
++reallocarray_musl_dep = declare_dependency(link_with: [static_library('reallocarray_musl', 'src/malloc/reallocarray.c')])
+diff -u0 -r -N musl/src/malloc/reallocarray.c musl2/src/malloc/reallocarray.c
+--- musl/src/malloc/reallocarray.c
++++ musl2/src/malloc/reallocarray.c
+@@ -1 +0,0 @@
+-#define _BSD_SOURCE
A subprojects/reallocarray-musl.wrap => subprojects/reallocarray-musl.wrap +9 -0
@@ 0,0 1,9 @@
+# SPDX-FileCopyrightText: 2023 John Scott <jscott@posteo.net>
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Note that the above is meant to indicate the license that applies
+# to this very file, and not to Musl libc.
+[wrap-git]
+url = git://git.musl-libc.org/musl
+revision = master
+depth = 1
+diff_files = reallocarray-musl.patch
M which.c => which.c +1 -8
@@ 21,18 21,11 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
+void *reallocarray(void *, size_t, size_t);
/* A NULL-terminated list of directories in PATH. */
static char **list;
-static void *reallocarray(void *p, size_t m, size_t n) {
- if(n && m > SIZE_MAX / n) {
- errno = ENOMEM;
- return NULL;
- }
- return realloc(p, m * n);
-}
-
static bool file_is_executable(const char filename[restrict static 1]) {
struct stat st;
if(stat(filename, &st) == -1 || !S_ISREG(st.st_mode)) {