SCCS-vsn: usr.bin/tail/tail.c 4.6
-static char *sccsid = "@(#)tail.c 4.5 (Berkeley) %G%";
+#ifndef lint
+static char *sccsid = "@(#)tail.c 4.6 (Berkeley) %G%";
+#endif
/* tail command
*
* tail where [file]
/* tail command
*
* tail where [file]
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#define LBIN 8193
#include <errno.h>
#define LBIN 8193
if(!fromend&&n>0)
n--;
if(argc>2) {
if(!fromend&&n>0)
n--;
if(argc>2) {
if(open(argv[2],0)!=0) {
perror(argv[2]);
exit(1);
}
}
if(open(argv[2],0)!=0) {
perror(argv[2]);
exit(1);
}
}
+ (void)lseek(0,(off_t)0,L_INCR);
piped = errno==ESPIPE;
bylines = -1; bkwds = 0;
while(*arg)
piped = errno==ESPIPE;
bylines = -1; bkwds = 0;
while(*arg)
}
} while(*p++ != '\n');
}
}
} while(*p++ != '\n');
}
} else if(n>0) {
if(!piped)
} else if(n>0) {
if(!piped)
if(piped||(statb.st_mode&S_IFMT)==S_IFCHR)
while(n>0) {
i = n>BUFSIZ?BUFSIZ:n;
if(piped||(statb.st_mode&S_IFMT)==S_IFCHR)
while(n>0) {
i = n>BUFSIZ?BUFSIZ:n;
+ (void)lseek(0,(off_t)n,L_SET);
}
copy:
while((i=read(0,bin,BUFSIZ))>0)
}
copy:
while((i=read(0,bin,BUFSIZ))>0)
fexit();
/*seek from end*/
fexit();
/*seek from end*/
if(n <= 0)
fexit();
if(!piped) {
if(n <= 0)
fexit();
if(!piped) {
/* If by lines, back up 1 buffer: else back up as needed */
di = bylines?BUFSIZ:n;
if(statb.st_size > di)
/* If by lines, back up 1 buffer: else back up as needed */
di = bylines?BUFSIZ:n;
if(statb.st_size > di)
+ (void)lseek(0,(off_t)-di,L_XTND);
if(!bylines)
goto copy;
}
if(!bylines)
goto copy;
}
do {
if(--k<0) {
if(partial) {
do {
if(--k<0) {
if(partial) {
- if(bkwds) write(1,bin,lastnl+1);
+ if(bkwds)
+ (void)write(1,bin,lastnl+1);
goto brkb;
}
k = LBIN -1;
}
} while(bin[k]!='\n'&&k!=i);
if(bkwds && j>0){
goto brkb;
}
k = LBIN -1;
}
} while(bin[k]!='\n'&&k!=i);
if(bkwds && j>0){
- if(k<lastnl) write(1,&bin[k+1],lastnl-k);
+ if(k<lastnl) (void)write(1,&bin[k+1],lastnl-k);
- write(1,&bin[k+1],LBIN-k-1);
- write(1,bin,lastnl+1);
+ (void)write(1,&bin[k+1],LBIN-k-1);
+ (void)write(1,bin,lastnl+1);
}
}
} while(j++<n&&k!=i);
}
}
} while(j++<n&&k!=i);
} while(bin[k]!='\n'&&k!=i);
}
if(k<i)
} while(bin[k]!='\n'&&k!=i);
}
if(k<i)
- write(1,&bin[k+1],i-k-1);
+ (void)write(1,&bin[k+1],i-k-1);
- write(1,&bin[k+1],LBIN-k-1);
- write(1,bin,i);
+ (void)write(1,&bin[k+1],LBIN-k-1);
+ (void)write(1,bin,i);
for (;;)
{ sleep(1);
while ((n = read (0, bin, BUFSIZ)) > 0)
for (;;)
{ sleep(1);
while ((n = read (0, bin, BUFSIZ)) > 0)
+ (void)write (1, bin, n);