[Toybox] toybox - added cmp
Tim Elliott
tle at holymonkey.com
Wed Feb 8 01:13:21 PST 2012
On Tue, Feb 7, 2012 at 6:09 PM, Rob Landley <rob at landley.net> wrote:
> The optargs stuff recently grew "i#<0" where the <0 reads "at least 0",
> I.E. error out if this argument is less than 0.
That is nice. Looks like the default can go in there too.
>> * I noticed get_line() in lib/lib.c. Should I be using that instead?
>
> Probably. get_line() and get_rawline() read input a line at a time.
>
> I note that they do so with one syscall per character, but since I dunno
> how to push input back into a filehandle...
>
> (This was back when I was still resisting FILE * as unnecessary
> overhead. I got over it.)
Can you explain why get_rawline() reads input one char at a time, why
you would want to push data back into the filehandle, and why you
resisted FILE *? Hope I'm not distracting too much...
Hmm.. looking at get_rawline() in lib.c:
> for (;;) {
> if (1>read(fd, &c, 1)) break;
> if (!(len & 63)) buf=xrealloc(buf, len+65);
> if ((buf[len++]=c) == end) break;
> }
If the above gets a large input that has no newlines, won't it run out
of memory?
You go through a bit of effort to avoid a malloc/free here:
http://www.landley.net/hg/toybox/rev/7cff5420c90a#l20
Why is the extra xrealloc/free worthwhile for get_rawline()?
Cheers,
Tim
1328692401.0
More information about the Toybox
mailing list