Gentoo Archives: gentoo-dev

From: Oskari Pirhonen <xxc3ncoredxx@×××××.com>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH v3 1/2] esed.eclass: new eclass
Date: Tue, 07 Jun 2022 04:59:20
Message-Id: Yp7bG7vGpdjQHjOr@dj3ntoo
In Reply to: Re: [gentoo-dev] [PATCH v3 1/2] esed.eclass: new eclass by Oskari Pirhonen
1 On Sun, Jun 05, 2022 at 14:42:55 -0500, Oskari Pirhonen wrote:
2 > On Sat, Jun 04, 2022 at 16:46:33 -0400, Ionen Wolkens wrote:
3 > > +# Where possible, it is also good to consider if using patches is more
4 > > +# suitable to ensure adequate changes. These functions are also unsafe
5 > > +# for binary files containing null bytes (erepl() will remove them).
6 >
7 > Some way to test for NULL in the file before reading might be useful.
8 > Possibly die if found? Although right now I can't think of a super
9 > elegant and/or efficient way to do so without writing a simple external
10 > helper.
11 >
12
13 I came up with _an_ idea. It feels kinda hacky, goes against my previous
14 statement wrt running sed on binary files, but it seems to work based on
15 some quick tests:
16
17 [ /tmp ]
18 oskari@dj3ntoo λ null_free() {
19 > [[ $(sed -ne '/\x00/{p;q}' "$1" | wc -c) -eq 0 ]]
20 > }
21 [ /tmp ]
22 oskari@dj3ntoo λ for f in test*.dat; do
23 > echo "${f}:"
24 > hd $f
25 > null_free $f || echo "has null"
26 > done
27 test1.dat:
28 00000000 61 62 0a 63 64 00 65 66 |ab.cd.ef|
29 00000008
30 has null
31 test2.dat:
32 00000000 67 68 0a 69 6a 0a 6b 6c |gh.ij.kl|
33 00000008
34 test3.dat:
35 00000000 00 0a 31 32 0a 33 34 |..12.34|
36 00000007
37 has null
38 test4.dat:
39 00000000 61 61 00 61 61 0a 62 62 00 62 62 0a 63 63 00 63 |aa.aa.bb.bb.cc.c|
40 00000010 63 |c|
41 00000011
42 has null
43
44 - Oskari

Attachments

File name MIME type
signature.asc application/pgp-signature