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