On Sun, Jun 05, 2022 at 14:42:55 -0500, Oskari Pirhonen wrote: > On Sat, Jun 04, 2022 at 16:46:33 -0400, Ionen Wolkens wrote: > > +# Where possible, it is also good to consider if using patches is more > > +# suitable to ensure adequate changes. These functions are also unsafe > > +# for binary files containing null bytes (erepl() will remove them). > > Some way to test for NULL in the file before reading might be useful. > Possibly die if found? Although right now I can't think of a super > elegant and/or efficient way to do so without writing a simple external > helper. >
I came up with _an_ idea. It feels kinda hacky, goes against my previous statement wrt running sed on binary files, but it seems to work based on some quick tests: [ /tmp ] oskari@dj3ntoo λ null_free() { > [[ $(sed -ne '/\x00/{p;q}' "$1" | wc -c) -eq 0 ]] > } [ /tmp ] oskari@dj3ntoo λ for f in test*.dat; do > echo "${f}:" > hd $f > null_free $f || echo "has null" > done test1.dat: 00000000 61 62 0a 63 64 00 65 66 |ab.cd.ef| 00000008 has null test2.dat: 00000000 67 68 0a 69 6a 0a 6b 6c |gh.ij.kl| 00000008 test3.dat: 00000000 00 0a 31 32 0a 33 34 |..12.34| 00000007 has null test4.dat: 00000000 61 61 00 61 61 0a 62 62 00 62 62 0a 63 63 00 63 |aa.aa.bb.bb.cc.c| 00000010 63 |c| 00000011 has null - Oskari
signature.asc
Description: PGP signature