tail cleanup

This commit is contained in:
Connor Lane Smith 2011-05-26 16:29:22 -01:00
parent a2be57eca8
commit ad442060b8

8
tail.c
View File

@ -9,14 +9,13 @@
static void dropinit(FILE *, const char *, long); static void dropinit(FILE *, const char *, long);
static void taketail(FILE *, const char *, long); static void taketail(FILE *, const char *, long);
static void (*tail)(FILE *, const char *, long) = taketail;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *end, c; char *end, c;
long n = 10; long n = 10;
FILE *fp; FILE *fp;
void (*tail)(FILE *, const char *, long) = taketail;
while((c = getopt(argc, argv, "n:")) != -1) while((c = getopt(argc, argv, "n:")) != -1)
switch(c) { switch(c) {
@ -67,6 +66,8 @@ taketail(FILE *fp, const char *str, long n)
eprintf("calloc:"); eprintf("calloc:");
for(i = j = 0; afgets(&ring[i], &size[i], fp); i = j = (i+1)%n) for(i = j = 0; afgets(&ring[i], &size[i], fp); i = j = (i+1)%n)
; ;
if(ferror(fp))
eprintf("%s: read error:", str);
do { do {
if(ring[j]) { if(ring[j]) {
@ -76,7 +77,4 @@ taketail(FILE *fp, const char *str, long n)
} while((j = (j+1)%n) != i); } while((j = (j+1)%n) != i);
free(ring); free(ring);
free(size); free(size);
if(ferror(fp))
eprintf("%s: read error:", str);
} }