diff options
author | paul <paul@FreeBSD.org> | 2004-11-04 19:18:19 +0000 |
---|---|---|
committer | paul <paul@FreeBSD.org> | 2004-11-04 19:18:19 +0000 |
commit | 4b813e782f86ea86dc503cbcdf096391e47023ed (patch) | |
tree | 7f9ec10647bbe930e464447c09ec4505e398b99c /usr.bin/tail/tail.c | |
parent | 174862f7bbe6e86b700b32335962130383967180 (diff) | |
download | FreeBSD-src-4b813e782f86ea86dc503cbcdf096391e47023ed.zip FreeBSD-src-4b813e782f86ea86dc503cbcdf096391e47023ed.tar.gz |
Add support for following more than one file i.e.
tail -f file1 file2
Diffstat (limited to 'usr.bin/tail/tail.c')
-rw-r--r-- | usr.bin/tail/tail.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c index 2a3ee13..9162d17 100644 --- a/usr.bin/tail/tail.c +++ b/usr.bin/tail/tail.c @@ -60,9 +60,11 @@ static const char sccsid[] = "@(#)tail.c 8.1 (Berkeley) 6/6/93"; #include "extern.h" -int Fflag, fflag, rflag, rval; +int Fflag, fflag, rflag, rval, no_files; const char *fname; +file_info_t *files; + static void obsolete(char **); static void usage(void); @@ -73,7 +75,8 @@ main(int argc, char *argv[]) FILE *fp; off_t off; enum STYLE style; - int ch, first; + int i, ch, first; + file_info_t *file; char *p; /* @@ -138,8 +141,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (fflag && argc > 1) - errx(1, "-f option only appropriate for a single file"); + no_files = argc ? argc : 1; /* * If displaying in reverse, don't permit follow option, and convert @@ -168,7 +170,29 @@ main(int argc, char *argv[]) } } - if (*argv) + if (*argv && fflag) { + files = (struct file_info *) malloc(no_files * sizeof(struct file_info)); + if (! files) + err(1, "Couldn't malloc space for file descriptors."); + + for (file = files; (fname = *argv++); file++) { + file->file_name = malloc(strlen(fname)+1); + if (! file->file_name) + errx(1, "Couldn't malloc space for file name."); + strncpy(file->file_name, fname, strlen(fname)+1); + if ((file->fp = fopen(file->file_name, "r")) == NULL || + fstat(fileno(file->fp), &file->st)) { + file->fp = NULL; + ierr(); + continue; + } + } + follow(files, style, off); + for (i = 0, file = files; i < no_files; i++, file++) { + free(file->file_name); + } + free(files); + } else if (*argv) { for (first = 1; (fname = *argv++);) { if ((fp = fopen(fname, "r")) == NULL || fstat(fileno(fp), &sb)) { @@ -186,9 +210,8 @@ main(int argc, char *argv[]) reverse(fp, style, off, &sb); else forward(fp, style, off, &sb); - (void)fclose(fp); } - else { + } else { fname = "stdin"; if (fstat(fileno(stdin), &sb)) { |