diff options
author | Ilya Kuzmich <ilya.kuzmich@gmail.com> | 2017-05-29 07:05:16 +0300 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-07-02 20:28:47 -0500 |
commit | 24dfc146470aa8098c49f37a6f10a0687aa66c72 (patch) | |
tree | 6e412a33e84a08f395335a609cbfd808e7262943 /toys/posix | |
parent | b8e0920c180f81f86f0888804445f67a2a76fe2b (diff) | |
download | toybox-24dfc146470aa8098c49f37a6f10a0687aa66c72.tar.gz |
strings tests and bugfixes
Fixes missing newline in output if last byte of the input is string.
Fixes one-off offset bug.
Adds strings tests.
Signed-off-by: Ilya Kuzmich <ilya.kuzmich@gmail.com>
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/strings.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/toys/posix/strings.c b/toys/posix/strings.c index f3ce70ce..d2154e79 100644 --- a/toys/posix/strings.c +++ b/toys/posix/strings.c @@ -38,7 +38,10 @@ static void do_strings(int fd, char *filename) for (;;) { nread = read(fd, toybuf, sizeof(toybuf)); if (nread < 0) perror_msg_raw(filename); - if (nread < 1) break; + if (nread < 1) { + if (count == wlen) xputc('\n'); + break; + } for (i = 0; i < nread; i++, offset++) { if (((toybuf[i] >= 32) && (toybuf[i] <= 126)) || (toybuf[i] == '\t')) { if (count == wlen) fputc(toybuf[i], stdout); @@ -47,7 +50,7 @@ static void do_strings(int fd, char *filename) if (count == wlen) { if (toys.optflags & FLAG_f) printf("%s: ", filename); if (toys.optflags & FLAG_o) - printf("%7lld ",(long long)(offset - wlen)); + printf("%7lld ",(long long)(offset + 1 - wlen)); printf("%s", string); } } |