[Toybox] [CLEANUP] strings
Rob Landley
rob at landley.net
Wed Jun 11 06:05:33 PDT 2014
Commit http://landley.net/hg/toybox/rev/1349
Tweak help so -N is consistently using "LEN" isntead of sometimes "count".
Redo the read() part to catch errors in reading from the file. (I'd like
to have a warning-only version of xread() but we'd still have to check
for errors on return to break out of the file, so it wouldn't save us
much. Have to think about it...)
This doesn't handle UTF8 strings. At some point in the future I may want
to redo it so it does. (I guess 4 consecutive valid utf8 characters
count as a hit, and then continue as long as the utf8 sequences are
valid? Not sure how that would affect the false positive rate...)
Posix wants -t and hex output, this doesn't do that. Might also revisit
for that. Accept (and ignore) -a.
Redo output so only the newline is using xputc(), and the other stuff is
using printf() and fputc(). The rationale is to let the stdio buffer do
its thing, rather than making a syscall for every byte. Hopefully if we
have a short write stdio will notice and either retry or set the error
flag, and then xputc() catches the error flag and the error case of
nontransient output failure (disk full, pipe to a dead process, etc).
For the common case stdio should buffer the output and xputc flush it
anyway.
trivial: I made wlen be equal to TT.len instead of TT.len-1, had the
assignment postincrement, and checked for equality rather than greater
than. (Having the constraint be TT.len-1 and the allocation be TT.len+1
looked like a fencepost error. It wasn't, but I didn't want other
readers to have to work out why.)
Couple whitespace tweaks. Other than that, it was in pretty good shape.
Rob
1402491933.0
More information about the Toybox
mailing list