[Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

enh enh at google.com
Mon Apr 22 15:17:50 PDT 2024


On Mon, Apr 22, 2024 at 2:23 PM Oliver Webb <aquahobbyist at proton.me> wrote:
>
> > On Sat, Apr 20, 2024 at 7:38 PM Oliver Webb via Toybox
> > toybox at lists.landley.net wrote:
>
> > > xxd also runs on average about 5 times slower than vim xxd, this is
> > > because of read reading 16 bytes at a time, also not hard to fix, but
> > > very hard to fix cleanly.
> >
> >
> > really? a quick glance suggests it reads blocks of sizeof(toybuf)? (or
> > "whatever stdio is using for its buffer" in the -r case.)
>
> strace-ing it shows:
>
> read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 16
>
> And if you pass in -c 12 to it:
>
> read(0, "\0\0\0\0\0\0\0\0\0\0\0\0", 12) = 12
>
> In practice, it's always what -c is

ah, yeah, the _include_ path uses the full buffer and -r uses stdio
buffering, but "regular" xxd was doing neither. i've sent out the
trivial patch to switch to stdio.

> > > xxd has a -d flag to do decimal address lables that I added in this patch.
> >
> > do you have a use for that? i saw it and ignored it when
> > implementing toybox xxd because i couldn't even imagine a use for
> > decimal addresses...
>
> Trying to do math with them in awk or expr or some other program where numbers
> are always read as base 10:
>
> $ head -c 0xf
> head: invalid number of bytes: ‘0xf’
>
> I think the ability to read base 16 numbers and prefixes in toybox is a really
> cool consequence of everything being in one binary. But almost every other utility
> set doesn't have it because most aren't multi-call binaries.
>
> - Oliver Webb aquahobbyist at proton.me
>


More information about the Toybox mailing list