X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Ftail.c;h=df881a37a19263c94b59800a6a856e7c5766672f;hb=982aa263a0cef10ee4f4c06084a87af736c449ac;hp=0be16631509aef0ded97004e9ee64bb3ab526a63;hpb=043b1e5d997d9b582a5aee37bd56e2e4f29be6e4;p=oweals%2Fbusybox.git diff --git a/coreutils/tail.c b/coreutils/tail.c index 0be166315..df881a37a 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -4,7 +4,7 @@ * * Copyright (C) 2001 by Matt Kraai * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ /* BB_AUDIT SUSv3 compliant (need fancy for -c) */ @@ -35,7 +35,7 @@ static const struct suffix_mult tail_suffixes[] = { struct globals { bool status; -}; +} FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) static void tail_xprint_header(const char *fmt, const char *filename) @@ -66,7 +66,7 @@ static ssize_t tail_read(int fd, char *buf, size_t count) return r; } -static const char header_fmt[] ALIGN1 = "\n==> %s <==\n"; +#define header_fmt_str "\n==> %s <==\n" static unsigned eat_num(const char *p) { @@ -166,7 +166,7 @@ int tail_main(int argc, char **argv) tailbuf = xmalloc(tailbufsize); /* tail the files */ - fmt = header_fmt + 1; /* skip header leading newline on first output */ + fmt = header_fmt_str + 1; /* skip header leading newline on first output */ i = 0; do { char *buf; @@ -181,7 +181,7 @@ int tail_main(int argc, char **argv) if (nfiles > header_threshhold) { tail_xprint_header(fmt, argv[i]); - fmt = header_fmt; + fmt = header_fmt_str; } if (!from_top) { @@ -241,7 +241,8 @@ int tail_main(int argc, char **argv) } while (nwrite); } } - xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite); + if (nwrite > 0) + xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite); } else if (count) { if (COUNT_BYTES) { taillen += nread; @@ -332,7 +333,7 @@ int tail_main(int argc, char **argv) if (ENABLE_FEATURE_FANCY_TAIL && fd < 0) continue; if (nfiles > header_threshhold) { - fmt = header_fmt; + fmt = header_fmt_str; } while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) { if (fmt) { @@ -345,6 +346,7 @@ int tail_main(int argc, char **argv) } if (ENABLE_FEATURE_CLEAN_UP) { free(fds); + free(tailbuf); } return G.status; }