From 03600a8c07b89dcad1c3ec21d1d2c01673e278e3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 6 Aug 2019 14:02:41 -0400 Subject: working tail bytes --- tail.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tail.c b/tail.c index b6e49ba..742fed8 100644 --- a/tail.c +++ b/tail.c @@ -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) { -- cgit v1.2.1