summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-06 14:02:41 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-06 14:02:41 -0400
commit03600a8c07b89dcad1c3ec21d1d2c01673e278e3 (patch)
treea9cb7c968ce46148ca2feddad61cf15b4090f8ef
parent34683670f095834a8e51ea3c2c81fbd81595db03 (diff)
working tail bytes
-rw-r--r--tail.c14
1 files changed, 13 insertions, 1 deletions
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) {