refresh busybox patches
[openwrt/svn-archive/archive.git] / package / busybox / patches / 990-upstream_tail_fix.patch
1 Index: busybox-1.7.2/coreutils/tail.c
2 ===================================================================
3 --- busybox-1.7.2.orig/coreutils/tail.c 2007-10-30 15:34:59.000000000 -0500
4 +++ busybox-1.7.2/coreutils/tail.c 2007-10-30 15:35:06.000000000 -0500
5 @@ -47,13 +47,16 @@
6 static ssize_t tail_read(int fd, char *buf, size_t count)
7 {
8 ssize_t r;
9 - off_t current, end;
10 + off_t current;
11 struct stat sbuf;
12
13 - end = current = lseek(fd, 0, SEEK_CUR);
14 - if (!fstat(fd, &sbuf))
15 - end = sbuf.st_size;
16 - lseek(fd, end < current ? 0 : current, SEEK_SET);
17 + /* (A good comment is missing here) */
18 + current = lseek(fd, 0, SEEK_CUR);
19 + /* /proc files report zero st_size, don't lseek them. */
20 + if (fstat(fd, &sbuf) == 0 && sbuf.st_size)
21 + if (sbuf.st_size < current)
22 + lseek(fd, 0, SEEK_SET);
23 +
24 r = safe_read(fd, buf, count);
25 if (r < 0) {
26 bb_perror_msg(bb_msg_read_error);
27 @@ -67,8 +70,12 @@
28
29 static unsigned eat_num(const char *p)
30 {
31 - if (*p == '-') p++;
32 - else if (*p == '+') { p++; G.status = EXIT_FAILURE; }
33 + if (*p == '-')
34 + p++;
35 + else if (*p == '+') {
36 + p++;
37 + G.status = EXIT_FAILURE;
38 + }
39 return xatou_sfx(p, tail_suffixes);
40 }
41