diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-06 14:02:41 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-06 14:02:41 -0400 |
commit | 03600a8c07b89dcad1c3ec21d1d2c01673e278e3 (patch) | |
tree | a9cb7c968ce46148ca2feddad61cf15b4090f8ef /tail.c | |
parent | 34683670f095834a8e51ea3c2c81fbd81595db03 (diff) |
working tail bytes
Diffstat (limited to 'tail.c')
-rw-r--r-- | tail.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -59,7 +59,19 @@ static int tail(const char *path, int follow, int unit, intmax_t count) } while (count < 0) { - /* work from the end */ + count = (-count) + 1; + if (unit == BYTES) { + char buf[count]; + intmax_t pos = 0; + while ((c = getc(f)) != EOF) { + buf[pos++] = c; + if (pos >= count) { + pos = 0; + } + } + fwrite(buf + pos, 1, count - pos, stdout); + fwrite(buf, 1, pos, stdout); + } } while (follow) { |