static int taillen;
static int newline;
-void tailbuf_append(char *buf, int len)
+static void tailbuf_append(char *buf, int len)
{
tailbuf = xrealloc(tailbuf, taillen + len);
memcpy(tailbuf + taillen, buf, len);
taillen += len;
}
-void tailbuf_trunc()
+static void tailbuf_trunc()
{
char *s;
s = memchr(tailbuf, '\n', taillen);
case 'f':
follow = 1;
break;
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
case 'c':
units = BYTES;
/* FALLS THROUGH */
if (optarg[0] == '+')
from_top = 1;
break;
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
case 'q':
hide_headers = 1;
break;
}
}
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
/* tail the files */
if (!from_top && units == BYTES)
tailbuf = xmalloc(count);
for (i = 0; i < nfiles; i++) {
if (fds[i] == -1)
continue;
+ if (!count) {
+ lseek(fds[i], 0, SEEK_END);
+ continue;
+ }
seen = 0;
if (show_headers || (!hide_headers && nfiles > 1))
printf("%s==> %s <==\n", i == 0 ? "" : "\n", argv[optind + i]);
while ((nread = safe_read(fds[i], buf, sizeof(buf))) > 0) {
if (from_top) {
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
if (units == BYTES) {
if (count - 1 <= seen)
nwrite = nread;
break;
}
} else {
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
if (units == BYTES) {
if (nread < count) {
memmove(tailbuf, tailbuf + nread, count - nread);
status = EXIT_FAILURE;
}
-#ifndef BB_FEATURE_SIMPLE_TAIL
+#ifdef BB_FEATURE_FANCY_TAIL
if (!from_top && units == BYTES) {
if (count < seen)
seen = count;