[Toybox] [PATCH] Start replacing get_line() with getline().

enh enh at google.com
Fri Jul 19 09:55:00 PDT 2019


I started this last night, but thought I'd aim to send multiple small
patches rather than work through all the callers and send one big patch.

I've deliberately chosen the ugly name `allocated_length` because we've
had historical bugs where folks think this a line length in the sense of
the return value. I do wonder whether we should actually have some kind
of getline() wrapper that hides the `char *`/`size_t` pair in lib/,
which makes the function easier to use in most cases but does add the
less common gotcha that you wouldn't be able to getline() through
multiple files at once (which does happen in at least one toy).

But maybe the real fix is to look harder for places where we can just
use loopfiles_lines? Speaking of which, should we actually add two more
arguments to that? Specifically: switch it to getdelim() rather than
getline() behind the scenes, and also add a way to have the trailing
'\n' automatically removed, since that seems to be what most callers
want?

Anyway, that seemed like enough questions that it was time to send this
initial patch out before doing too much more...
---
 lib/password.c        |  9 +++++----
 toys/other/rev.c      | 26 ++++++++++++--------------
 toys/posix/uudecode.c | 21 +++++++++++++--------
 3 files changed, 30 insertions(+), 26 deletions(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Start-replacing-get_line-with-getline.patch
Type: text/x-patch
Size: 5176 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20190719/db813d87/attachment-0002.bin>


More information about the Toybox mailing list