summaryrefslogtreecommitdiff
path: root/coreutils/tail.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/tail.c')
-rw-r--r--coreutils/tail.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 74e14232d..8a112346d 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -47,13 +47,16 @@ static void tail_xprint_header(const char *fmt, const char *filename)
47static ssize_t tail_read(int fd, char *buf, size_t count) 47static ssize_t tail_read(int fd, char *buf, size_t count)
48{ 48{
49 ssize_t r; 49 ssize_t r;
50 off_t current, end; 50 off_t current;
51 struct stat sbuf; 51 struct stat sbuf;
52 52
53 end = current = lseek(fd, 0, SEEK_CUR); 53 /* (A good comment is missing here) */
54 if (!fstat(fd, &sbuf)) 54 current = lseek(fd, 0, SEEK_CUR);
55 end = sbuf.st_size; 55 /* /proc files report zero st_size, don't lseek them. */
56 lseek(fd, end < current ? 0 : current, SEEK_SET); 56 if (fstat(fd, &sbuf) == 0 && sbuf.st_size)
57 if (sbuf.st_size < current)
58 lseek(fd, 0, SEEK_SET);
59
57 r = safe_read(fd, buf, count); 60 r = safe_read(fd, buf, count);
58 if (r < 0) { 61 if (r < 0) {
59 bb_perror_msg(bb_msg_read_error); 62 bb_perror_msg(bb_msg_read_error);
@@ -67,8 +70,12 @@ static const char header_fmt[] ALIGN1 = "\n==> %s <==\n";
67 70
68static unsigned eat_num(const char *p) 71static unsigned eat_num(const char *p)
69{ 72{
70 if (*p == '-') p++; 73 if (*p == '-')
71 else if (*p == '+') { p++; G.status = EXIT_FAILURE; } 74 p++;
75 else if (*p == '+') {
76 p++;
77 G.status = EXIT_FAILURE;
78 }
72 return xatou_sfx(p, tail_suffixes); 79 return xatou_sfx(p, tail_suffixes);
73} 80}
74 81