Changeset View
Changeset View
Standalone View
Standalone View
tail/tail.c
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | #define ARG(units, forward, backward) { \ | ||||
} | } | ||||
if (*argv && fflag) { | if (*argv && fflag) { | ||||
files = (struct file_info *) malloc(no_files * | files = (struct file_info *) malloc(no_files * | ||||
sizeof(struct file_info)); | sizeof(struct file_info)); | ||||
if (!files) | if (!files) | ||||
err(1, "Couldn't malloc space for file descriptors."); | err(1, "Couldn't malloc space for file descriptors."); | ||||
for (file = files; (fn = *argv++); file++) { | for (file = files; (fn = *argv++); file++) { | ||||
oshogbo: Maybe we can take this code and make a function from it, and below init it with single file… | |||||
Done Inline ActionsMight be better to do that in a separate review. swills: Might be better to do that in a separate review. | |||||
file->file_name = strdup(fn); | file->file_name = strdup(fn); | ||||
if (! file->file_name) | if (! file->file_name) | ||||
errx(1, "Couldn't malloc space for file name."); | errx(1, "Couldn't malloc space for file name."); | ||||
file->fp = fileargs_fopen(fa, file->file_name, "r"); | file->fp = fileargs_fopen(fa, file->file_name, "r"); | ||||
if (file->fp == NULL || | if (file->fp == NULL || | ||||
fstat(fileno(file->fp), &file->st)) { | fstat(fileno(file->fp), &file->st)) { | ||||
if (file->fp != NULL) { | if (file->fp != NULL) { | ||||
fclose(file->fp); | fclose(file->fp); | ||||
Show All 40 Lines | if (*argv && fflag) { | ||||
if (lseek(fileno(stdin), (off_t)0, SEEK_CUR) == -1 && | if (lseek(fileno(stdin), (off_t)0, SEEK_CUR) == -1 && | ||||
errno == ESPIPE) { | errno == ESPIPE) { | ||||
errno = 0; | errno = 0; | ||||
fflag = 0; /* POSIX.2 requires this. */ | fflag = 0; /* POSIX.2 requires this. */ | ||||
} | } | ||||
if (rflag) | if (rflag) | ||||
reverse(stdin, fn, style, off, &sb); | reverse(stdin, fn, style, off, &sb); | ||||
else | else { | ||||
forward(stdin, fn, style, off, &sb); | forward(stdin, fn, style, off, &sb); | ||||
if (fflag) { | |||||
file = (struct file_info *) malloc(sizeof(struct file_info)); | |||||
Done Inline ActionsMissing error checking. oshogbo: Missing error checking. | |||||
file->file_name = strdup(fn); | |||||
Done Inline ActionsMissing error checking. oshogbo: Missing error checking. | |||||
file->fp = stdin; | |||||
follow(file, style, off); | |||||
free(file); | |||||
} | |||||
} | |||||
} | } | ||||
fileargs_free(fa); | fileargs_free(fa); | ||||
exit(rval); | exit(rval); | ||||
} | } | ||||
/* | /* | ||||
* Convert the obsolete argument form into something that getopt can handle. | * Convert the obsolete argument form into something that getopt can handle. | ||||
* This means that anything of the form [+-][0-9][0-9]*[lbc][Ffr] that isn't | * This means that anything of the form [+-][0-9][0-9]*[lbc][Ffr] that isn't | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |
Maybe we can take this code and make a function from it, and below init it with single file, and here with whole argv and argc?