* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)tail.c 5.3 (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
!='+') {
(void)lseek(0,(off_t
)0,L_INCR
);
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
)
(void)lseek(0,(off_t
)n
,L_SET
);
while((i
=read(0,bin
,BUFSIZ
))>0)
/* If by lines, back up 1 buffer: else back up as needed */
(void)lseek(0,(off_t
)-di
,L_XTND
);
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;}
(void)write(1,bin
,lastnl
+1);
} while(bin
[k
]!='\n'&&k
!=i
);
if(k
<lastnl
) (void)write(1,&bin
[k
+1],lastnl
-k
);
(void)write(1,&bin
[k
+1],LBIN
-k
-1);
(void)write(1,bin
,lastnl
+1);
} while(bin
[k
]!='\n'&&k
!=i
);
(void)write(1,&bin
[k
+1],i
-k
-1);
(void)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)
if (write (1, bin
, n
) < 0)