summaryrefslogtreecommitdiffstats
path: root/usr.bin/tail/read.c
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2003-06-10 16:49:14 +0000
committermarkm <markm@FreeBSD.org>2003-06-10 16:49:14 +0000
commitd152e35c1474fba5e67d01115545afd3d8ba2fdb (patch)
tree9aea54f6e980347ef2870e33cf444d5a677f18d9 /usr.bin/tail/read.c
parente46b9f99caad85af7d27e370f7abf6a6da46cbd0 (diff)
downloadFreeBSD-src-d152e35c1474fba5e67d01115545afd3d8ba2fdb.zip
FreeBSD-src-d152e35c1474fba5e67d01115545afd3d8ba2fdb.tar.gz
Revert part of the last commit. This fixes tail for pipes.
Submitted by: joerg
Diffstat (limited to 'usr.bin/tail/read.c')
-rw-r--r--usr.bin/tail/read.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/usr.bin/tail/read.c b/usr.bin/tail/read.c
index b8112fe..f904ef0 100644
--- a/usr.bin/tail/read.c
+++ b/usr.bin/tail/read.c
@@ -140,14 +140,13 @@ lines(fp, off)
off_t off;
{
struct {
- u_int blen;
+ int blen;
u_int len;
char *l;
} *llines;
int ch;
char *p, *sp;
- int recno, wrap;
- u_int cnt, blen;
+ int blen, cnt, recno, wrap;
if ((llines = malloc(off * sizeof(*llines))) == NULL)
err(1, "malloc");
@@ -163,7 +162,7 @@ lines(fp, off)
}
*p++ = ch;
if (ch == '\n') {
- if (llines[recno].blen < cnt) {
+ if ((int)llines[recno].blen < cnt) {
llines[recno].blen = cnt + 256;
if ((llines[recno].l = realloc(llines[recno].l,
llines[recno].blen)) == NULL)
@@ -192,16 +191,16 @@ lines(fp, off)
}
if (rflag) {
- for (cnt = recno - 1; cnt != 0; --cnt)
+ for (cnt = recno - 1; cnt >= 0; --cnt)
WR(llines[cnt].l, llines[cnt].len);
if (wrap)
- for (cnt = off - 1; cnt >= (u_int)recno; --cnt)
+ for (cnt = off - 1; cnt >= recno; --cnt)
WR(llines[cnt].l, llines[cnt].len);
} else {
if (wrap)
- for (cnt = recno; cnt < (u_int)off; ++cnt)
+ for (cnt = recno; cnt < off; ++cnt)
WR(llines[cnt].l, llines[cnt].len);
- for (cnt = 0; cnt < (u_int)recno; ++cnt)
+ for (cnt = 0; cnt < recno; ++cnt)
WR(llines[cnt].l, llines[cnt].len);
}
return 0;
OpenPOWER on IntegriCloud