static char *sccsid
= "@(#)tail.c 4.1 (Berkeley) %G%";
* - means n lines before end
* + means nth line from beginning
* type 'b' means tail n blocks, not lines
* type 'c' means tail n characters
* Type 'r' means in lines in reverse order from end
* (for -r, default is entire buffer )
* option 'f' means loop endlessly trying to read more
* characters after the end of file, on the assumption
* that the file is growing
int partial
,bylines
,bkwds
,fromend
,lastnl
;
if(argc
<=1 || *arg
!='-'&&*arg
!='+') {
if(bylines
!=-1) goto errcom
;
if(bylines
!=-1) goto errcom
;
bkwds
= 1; fromend
= 1; bylines
= 1;
if(bylines
!=-1) goto errcom
;
if(bylines
==-1) bylines
= 1;
if(piped
||(statb
.st_mode
&S_IFMT
)==S_IFCHR
)
while((i
=read(0,bin
,BUFSIZ
))>0)
di
= !bylines
&&n
<LBIN
?n
:LBIN
-1;
j
= read(0,&bin
[i
],LBIN
-i
);
if(bkwds
&& bin
[i
==0?LBIN
-1:i
-1]!='\n'){ /* force trailing newline */
if(++i
>=LBIN
) {i
= 0; partial
= 0;}
if(bkwds
) write(1,bin
,lastnl
+1);
} while(bin
[k
]!='\n'&&k
!=i
);
if(k
<lastnl
) write(1,&bin
[k
+1],lastnl
-k
);
write(1,&bin
[k
+1],LBIN
-k
-1);
} while(bin
[k
]!='\n'&&k
!=i
);
write(1,&bin
[k
+1],i
-k
-1);
write(1,&bin
[k
+1],LBIN
-k
-1);
fprintf(stderr
, "usage: tail [+\b_[n][lbc][rf]] [file]\n");
if (!follow
|| piped
) exit(0);
while ((n
= read (0, bin
, BUFSIZ
)) > 0)