[Toybox] Embedded NUL bytes in grep/sed, or "strings are hard".
Rob Landley
rob at landley.net
Tue Sep 30 07:52:59 PDT 2014
On 09/30/14 09:27, Josiah Worcester wrote:
> On Tue, Sep 30, 2014 at 8:22 AM, Rob Landley <rob at landley.net
> <mailto:rob at landley.net>> wrote:
>
> The recent request to make grep work with embedded nul bytes (which
> impacts
> the design of sed and probably other stuff) is... tricky. Because line
> buffering is a nightmare.
>
> The problem is that while posix-2008 getline() will read an entire
> line to the
> next newline, returning embedded NUL bytes if any, it _won't_ tell
> you the
> length of the line it read. It returns a length, but that's the
> length of the
> allocated buffer, which is rounded up to who knows what and the
> extra data
> not necessarily zeroed.
>
>
> Actually it will: though that pointer-to-size_t argument in there is
> just the allocated buffer size, its return value actually is the length
> of the line it read. Sure, the interface is a bit rough, but it's not
> *quite* as insane as you might think. :)
Oh good. I can work with that.
Thanks,
Rob
1412088779.0
More information about the Toybox
mailing list