Skip to content

Commit 044cc7b

Browse files
committed
steps/utils-std-0.1.1: add upstream patches for reallocarray fallback
1 parent 8cde6de commit 044cc7b

4 files changed

Lines changed: 331 additions & 1 deletion

File tree

LICENSES/0BSD.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (C) YEAR by AUTHOR EMAIL
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

steps/SHA256SUMS.pkgs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ ab49972345d0c05f79b9370530829792e8c5c3b7fe283fc90e1dff26c2d0f6db tcc-0.9.27_2.t
148148
8576a7c99802bb462dd044ef7df7263192f1acfabde47462afd6145ffec1e4f1 tcc-0.9.27_3.tar.bz2
149149
252cc7226bef56e9dc591433ab2176cf1dd54dd18de20535edb708d5c6c21dce texinfo-7.2_0.tar.bz2
150150
b54b1aa40dc08eec51982fd581a64a900e2598ba29acc6ca9c2b1b2321603b49 util-linux-2.19.1_0.tar.bz2
151-
c1f666d6b88d124cae179eb4c67310fe9af8d1a610494a1c5f27473516acd61e utils-std-0.1.1_0.tar.bz2
151+
e56eb357986fea273309e72f2faa2b86da492e104ab216014d1b76526e242346 utils-std-0.1.1_0.tar.bz2
152152
9075b6832d8d7b094775c8e6ead763851aec96f4559d8cd62ce0a25e7a8a70ab which-2.21_0.tar.bz2
153153
d7357c5a73e4a0adb07220392316185716c42003fe7e63b63ba8493f12f3621b xz-5.6.4_0.tar.bz2
154154
9b10db90e06129fd174d48edb60a6d1e2fa72944fccef420431f8e836adcf972 zlib-1.3.1_0.tar.bz2

steps/utils-std-0.1.1/pass1.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ src_prepare() {
66
default
77

88
sed -i s/_Noreturn// libutils/err.h
9+
10+
# to avoid changing libtool checksums, although likely means better values
911
sed -i '/^commands="$/,/^"$/'s,getconf,, configure
1012
}
1113

1214
src_configure() {
15+
# patch(1) strips out permissions
16+
chmod +x configure
17+
1318
./configure PREFIX="${PREFIX}" CC=tcc AR=tcc\ -ar
1419
}
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
2+
SPDX-License-Identifier: MPL-2.0
3+
4+
diff --git utils-std-0.1.1/cmd/cut.c utils-std-0.1.1/cmd/cut.c
5+
index e56a4ca..2481759 100644
6+
--- utils-std-0.1.1/cmd/cut.c
7+
+++ utils-std-0.1.1/cmd/cut.c
8+
@@ -5,8 +5,8 @@
9+
#define _POSIX_C_SOURCE 202405L
10+
11+
#include "../config.h"
12+
-#include "../lib/reallocarray.h"
13+
#include "../libutils/getopt_nolong.h"
14+
+#include "../libutils/reallocarray.h"
15+
16+
#include <assert.h>
17+
#include <ctype.h>
18+
@@ -121,7 +121,7 @@ parse_list(char *s)
19+
20+
if(max > list_len)
21+
{
22+
- list = reallocarray(list, max, sizeof(*list));
23+
+ list = utils_reallocarray(list, max, sizeof(*list));
24+
if(list == NULL)
25+
{
26+
fprintf(stderr, "%s: error: Failed memory allocation: %s\n", argv0, strerror(errno));
27+
@@ -285,7 +285,7 @@ cut_c(FILE *in, const char *filename)
28+
29+
if(nread > line_wsz)
30+
{
31+
- line_w = reallocarray(line_w, nread, sizeof(*line_w));
32+
+ line_w = utils_reallocarray(line_w, nread, sizeof(*line_w));
33+
if(line_w == NULL)
34+
{
35+
fprintf(stderr, "%s: error: Failed memory allocation: %s\n", argv0, strerror(errno));
36+
diff --git utils-std-0.1.1/cmd/df.c utils-std-0.1.1/cmd/df.c
37+
index 85627a0..61082ca 100644
38+
--- utils-std-0.1.1/cmd/df.c
39+
+++ utils-std-0.1.1/cmd/df.c
40+
@@ -6,9 +6,9 @@
41+
#define _DEFAULT_SOURCE // mntent in glibc 2.19+
42+
43+
#include "../config.h"
44+
-#include "../lib/reallocarray.h"
45+
#include "../libutils/getopt_nolong.h"
46+
#include "../libutils/humanize.h"
47+
+#include "../libutils/reallocarray.h"
48+
49+
#include <ctype.h> // iscntrl, isspace
50+
#include <errno.h> // errno
51+
@@ -249,7 +249,7 @@ main(int argc, char *argv[])
52+
// So reallocarray to the rescue
53+
size_t devices_found = 0;
54+
size_t devices_len = 100;
55+
- devices = reallocarray(NULL, devices_len, sizeof(dev_t));
56+
+ devices = utils_reallocarray(NULL, devices_len, sizeof(dev_t));
57+
if(!devices)
58+
{
59+
fprintf(stderr,
60+
@@ -354,7 +354,7 @@ main(int argc, char *argv[])
61+
devices_len *= 2;
62+
if(devices_len <= 0) abort();
63+
64+
- devices = reallocarray(devices, devices_len, sizeof(dev_t));
65+
+ devices = utils_reallocarray(devices, devices_len, sizeof(dev_t));
66+
67+
if(!devices)
68+
{
69+
diff --git utils-std-0.1.1/cmd/join.c utils-std-0.1.1/cmd/join.c
70+
index ed93d92..f411a0a 100644
71+
--- utils-std-0.1.1/cmd/join.c
72+
+++ utils-std-0.1.1/cmd/join.c
73+
@@ -33,12 +33,11 @@
74+
* SUCH DAMAGE.
75+
*/
76+
77+
-#define _POSIX_C_SOURCE 202405L
78+
#define _BSD_SOURCE // fgetln, strsep
79+
80+
-#include "../lib/reallocarray.h"
81+
#include "../libutils/err.h"
82+
#include "../libutils/getopt_nolong.h"
83+
+#include "../libutils/reallocarray.h"
84+
85+
#include <assert.h>
86+
#include <errno.h>
87+
@@ -304,7 +303,7 @@ slurp(INPUT *F)
88+
cnt = F->setalloc;
89+
F->setalloc += 50;
90+
if(F->setalloc <= 0) utils_errx(1, "slurp setalloc overflow");
91+
- if((F->set = reallocarray(F->set, F->setalloc, sizeof(LINE))) == NULL)
92+
+ if((F->set = utils_reallocarray(F->set, F->setalloc, sizeof(LINE))) == NULL)
93+
utils_err(1, "Failed (re)allocating slurp set");
94+
memset(F->set + cnt, 0, 50 * sizeof(LINE));
95+
96+
@@ -356,7 +355,7 @@ slurp(INPUT *F)
97+
{
98+
lp->fieldalloc += 50;
99+
if(lp->fieldalloc < 0) utils_errx(1, "slurp fieldalloc overflow");
100+
- if((lp->fields = reallocarray(lp->fields, lp->fieldalloc, sizeof(char *))) == NULL)
101+
+ if((lp->fields = utils_reallocarray(lp->fields, lp->fieldalloc, sizeof(char *))) == NULL)
102+
utils_err(1, "Failed (re)allocating slurp fieldalloc");
103+
}
104+
lp->fields[lp->fieldcnt++] = fieldp;
105+
@@ -581,7 +580,7 @@ fieldarg(char *option)
106+
{
107+
olistalloc += 50;
108+
if(olistalloc <= 0) utils_errx(1, "fieldarg olistalloc overflow");
109+
- if((olist = reallocarray(olist, olistalloc, sizeof(OLIST))) == NULL)
110+
+ if((olist = utils_reallocarray(olist, olistalloc, sizeof(OLIST))) == NULL)
111+
utils_err(1, "Failed (re)allocating fieldarg");
112+
}
113+
olist[olistcnt].filenum = filenum;
114+
diff --git utils-std-0.1.1/common.mk utils-std-0.1.1/common.mk
115+
index 0b29a48..8d5be14 100644
116+
--- utils-std-0.1.1/common.mk
117+
+++ utils-std-0.1.1/common.mk
118+
@@ -9,4 +9,4 @@ lib/tr_str.o: lib/tr_str.c lib/tr_str.h
119+
cmd/cat: cmd/cat.c libutils/fs.o libutils/getopt_nolong.o
120+
cmd/printf: cmd/printf.c
121+
cmd/rm: cmd/rm.c libutils/consent.o libutils/getopt_nolong.o
122+
-cmd/tr: cmd/tr.c lib/tr_str.o libutils/err.o libutils/getopt_nolong.o
123+
+cmd/tr: cmd/tr.c lib/tr_str.o libutils/err.o libutils/getopt_nolong.o libutils/reallocarray.o
124+
diff --git utils-std-0.1.1/configure utils-std-0.1.1/configure
125+
index 7ccef56..d9905d2 100755
126+
--- utils-std-0.1.1/configure
127+
+++ utils-std-0.1.1/configure
128+
@@ -146,14 +146,14 @@ add_commands() {
129+
# when there's 3+ commands starting with the same letter, put them on a new line
130+
commands="
131+
arch base64 basename
132+
- cat chmod chown chroot cksum cmp date dirname
133+
+ cat chmod chown chroot cksum cmp cut date dirname
134+
echo env expr false getconf head id install link logname
135+
mesg mkdir mkfifo mktemp mv
136+
nice nohup nproc
137+
paste pathchk printf pwd
138+
realpath renice rm rmdir
139+
seq sha1sum sha256sum sha512sum shuf sleep split strings sync
140+
- tee test time timeout touch true truncate tty
141+
+ tee test time timeout touch tr true truncate tty
142+
uname uniq unlink
143+
wc which whoami yes
144+
"
145+
@@ -254,8 +254,7 @@ add_commands() {
146+
147+
echo
148+
149+
-check_header mntent.h
150+
-has_mntent_h=$?
151+
+check_header mntent.h && add_commands df
152+
153+
check_header sys/sysmacros.h && add_commands mknod
154+
155+
@@ -265,16 +264,13 @@ add_commands() {
156+
check_conftest configure.d/sendfile_linux.c && cpp_define HAS_SENDFILE
157+
check_conftest configure.d/copy_file_range.c && cpp_define HAS_COPY_FILE_RANGE
158+
159+
-check_conftest configure.d/reallocarray.c
160+
-has_reallocarray=$?
161+
-test 0 -eq $has_reallocarray && add_commands tr cut
162+
+check_conftest configure.d/reallocarray.c && cpp_define HAS_REALLOCARRAY
163+
164+
check_conftest configure.d/getopt_long.c && cpp_define HAS_GETOPT_LONG
165+
166+
check_conftest configure.d/syncfs.c && cpp_define HAS_SYNCFS
167+
168+
-check_conftest configure.d/fgetln.c
169+
-has_fgetln=$?
170+
+check_conftest configure.d/fgetln.c && add_commands join
171+
172+
check_conftest configure.d/mkstemps.c && cpp_define HAS_MKSTEMPS
173+
check_conftest configure.d/mkdtemps.c && cpp_define HAS_MKDTEMPS
174+
@@ -288,13 +284,6 @@ add_commands() {
175+
176+
echo
177+
178+
-if test 0 -eq $has_reallocarray; then
179+
- test 0 -eq $has_mntent_h && add_commands df
180+
- test 0 -eq $has_fgetln && add_commands join
181+
-fi
182+
-
183+
-echo
184+
-
185+
## Configuration write
186+
187+
printf 'Writing to config.mk ...'
188+
diff --git utils-std-0.1.1/configure.d/reallocarray.c utils-std-0.1.1/configure.d/reallocarray.c
189+
index 022df8f..426a6ce 100644
190+
--- utils-std-0.1.1/configure.d/reallocarray.c
191+
+++ utils-std-0.1.1/configure.d/reallocarray.c
192+
@@ -3,8 +3,7 @@
193+
// SPDX-License-Identifier: MPL-2.0
194+
195+
#define _POSIX_C_SOURCE 202405L
196+
-
197+
-#include "../lib/reallocarray.h"
198+
+#define _BSD_SOURCE
199+
200+
#include <stdlib.h> // reallocarray
201+
202+
diff --git utils-std-0.1.1/lib/reallocarray.h utils-std-0.1.1/lib/reallocarray.h
203+
deleted file mode 100644
204+
index 2d91abd..0000000
205+
--- utils-std-0.1.1/lib/reallocarray.h
206+
+++ /dev/null
207+
@@ -1,19 +0,0 @@
208+
-// utils-std: Collection of commonly available Unix tools
209+
-// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
210+
-// SPDX-License-Identifier: 0BSD
211+
-
212+
-#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 202405L
213+
-#error reallocarray needs: define _POSIX_C_SOURCE 202405L
214+
-#endif
215+
-
216+
-// pre-POSIX.1-2024 reallocarray fallback
217+
-#if !defined(_POSIX_VERSION) || _POSIX_VERSION < 202405L
218+
-#define _BSD_SOURCE
219+
-// FreeBSD
220+
-#undef _POSIX_C_SOURCE
221+
-#if __NetBSD_Version__ < 1000000000
222+
-#define _OPENBSD_SOURCE
223+
-#endif
224+
-#endif
225+
-
226+
-#include <stdlib.h> // reallocarray
227+
diff --git utils-std-0.1.1/lib/tr_str.c utils-std-0.1.1/lib/tr_str.c
228+
index 23dfcab..7cb14b9 100644
229+
--- utils-std-0.1.1/lib/tr_str.c
230+
+++ utils-std-0.1.1/lib/tr_str.c
231+
@@ -31,15 +31,12 @@
232+
* SUCH DAMAGE.
233+
*/
234+
235+
-// clang-format off
236+
#define _POSIX_C_SOURCE 202405L
237+
-// Needs to be the first included header due to this horrible BSD_VISIBLE macro
238+
-#include "./reallocarray.h"
239+
240+
#include "./tr_str.h"
241+
-// clang-format on
242+
243+
#include "../libutils/err.h"
244+
+#include "../libutils/reallocarray.h"
245+
246+
#include <assert.h>
247+
#include <ctype.h>
248+
@@ -190,7 +187,7 @@ genclass(STR *s)
249+
{
250+
len = NCHARS + 1;
251+
assert(len != 0);
252+
- cp->set = reallocarray(NULL, len, sizeof(*cp->set));
253+
+ cp->set = utils_reallocarray(NULL, len, sizeof(*cp->set));
254+
if(cp->set == NULL) utils_err(1, NULL);
255+
256+
len = 0;
257+
@@ -201,7 +198,7 @@ genclass(STR *s)
258+
cp->set[len++] = OOBCH;
259+
260+
assert(len != 0);
261+
- cp->set = reallocarray(cp->set, len, sizeof(*cp->set));
262+
+ cp->set = utils_reallocarray(cp->set, len, sizeof(*cp->set));
263+
if(cp->set == NULL) utils_err(1, NULL);
264+
}
265+
266+
diff --git utils-std-0.1.1/libutils/reallocarray.c utils-std-0.1.1/libutils/reallocarray.c
267+
new file mode 100644
268+
index 0000000..14b4fd8
269+
--- /dev/null
270+
+++ utils-std-0.1.1/libutils/reallocarray.c
271+
@@ -0,0 +1,30 @@
272+
+// Copied from musl
273+
+// Copyright © 2020 Ariadne Conill <ariadne@dereferenced.org>
274+
+// SPDX-License-Identifier: MIT
275+
+
276+
+#define _POSIX_C_SOURCE 202405L
277+
+#define _BSD_SOURCE
278+
+#include "./reallocarray.h"
279+
+
280+
+#include <errno.h>
281+
+#include <stdlib.h>
282+
+
283+
+#ifdef HAS_REALLOCARRAY
284+
+void *
285+
+utils_reallocarray(void *ptr, size_t m, size_t n)
286+
+{
287+
+ return reallocarray(ptr, m, n);
288+
+}
289+
+#else /* HAS_REALLOCARRAY */
290+
+void *
291+
+utils_reallocarray(void *ptr, size_t m, size_t n)
292+
+{
293+
+ if(n && m > -1 / n)
294+
+ {
295+
+ errno = ENOMEM;
296+
+ return 0;
297+
+ }
298+
+
299+
+ return realloc(ptr, m * n);
300+
+}
301+
+#endif
302+
diff --git utils-std-0.1.1/libutils/reallocarray.h utils-std-0.1.1/libutils/reallocarray.h
303+
new file mode 100644
304+
index 0000000..dcafb1e
305+
--- /dev/null
306+
+++ utils-std-0.1.1/libutils/reallocarray.h
307+
@@ -0,0 +1,13 @@
308+
+// utils-std: Collection of commonly available Unix tools
309+
+// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
310+
+// SPDX-License-Identifier: 0BSD
311+
+
312+
+#ifndef _BSD_SOURCE
313+
+# if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 202405L
314+
+# error reallocarray needs: define _POSIX_C_SOURCE 202405L or define _BSD_SOURCE
315+
+# endif
316+
+#endif
317+
+
318+
+#include <stdlib.h> // reallocarray
319+
+
320+
+void *utils_reallocarray(void *ptr, size_t m, size_t n);

0 commit comments

Comments
 (0)