Page MenuHomeFreeBSD

D31113.diff
No OneTemporary

D31113.diff

diff --git a/usr.bin/tail/extern.h b/usr.bin/tail/extern.h
--- a/usr.bin/tail/extern.h
+++ b/usr.bin/tail/extern.h
@@ -56,7 +56,7 @@
struct file_info {
FILE *fp;
- char *file_name;
+ const char *file_name;
struct stat st;
};
diff --git a/usr.bin/tail/tail.c b/usr.bin/tail/tail.c
--- a/usr.bin/tail/tail.c
+++ b/usr.bin/tail/tail.c
@@ -67,8 +67,6 @@
int Fflag, fflag, qflag, rflag, rval, no_files;
fileargs_t *fa;
-static file_info_t *files;
-
static void obsolete(char **);
static void usage(void);
@@ -88,8 +86,8 @@
FILE *fp;
off_t off;
enum STYLE style;
- int i, ch, first;
- file_info_t *file;
+ int ch, first;
+ file_info_t file, *filep, *files;
char *p;
cap_rights_t rights;
@@ -206,30 +204,24 @@
}
if (*argv && fflag) {
- files = (struct file_info *) malloc(no_files *
- sizeof(struct file_info));
- if (!files)
+ files = malloc(no_files * sizeof(struct file_info));
+ if (files == NULL)
err(1, "Couldn't malloc space for file descriptors.");
- for (file = files; (fn = *argv++); file++) {
- file->file_name = strdup(fn);
- if (! file->file_name)
- errx(1, "Couldn't malloc space for file name.");
- file->fp = fileargs_fopen(fa, file->file_name, "r");
- if (file->fp == NULL ||
- fstat(fileno(file->fp), &file->st)) {
- if (file->fp != NULL) {
- fclose(file->fp);
- file->fp = NULL;
+ for (filep = files; (fn = *argv++); filep++) {
+ filep->file_name = fn;
+ filep->fp = fileargs_fopen(fa, filep->file_name, "r");
+ if (filep->fp == NULL ||
+ fstat(fileno(filep->fp), &filep->st)) {
+ if (filep->fp != NULL) {
+ fclose(filep->fp);
+ filep->fp = NULL;
}
if (!Fflag || errno != ENOENT)
- ierr(file->file_name);
+ ierr(filep->file_name);
}
}
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; (fn = *argv++);) {
@@ -266,10 +258,15 @@
fflag = 0; /* POSIX.2 requires this. */
}
- if (rflag)
+ if (rflag) {
reverse(stdin, fn, style, off, &sb);
- else
+ } else if (fflag) {
+ file.file_name = fn;
+ file.fp = stdin;
+ follow(&file, style, off);
+ } else {
forward(stdin, fn, style, off, &sb);
+ }
}
fileargs_free(fa);
exit(rval);

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 4:56 AM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14670840
Default Alt Text
D31113.diff (2 KB)

Event Timeline