stat: assign fn before loop

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-02-14 14:48:24 +01:00 committed by sin
parent 780fd613eb
commit 68c3146a9d

12
stat.c
View File

@ -26,6 +26,7 @@ main(int argc, char *argv[])
int i, ret = EXIT_SUCCESS; int i, ret = EXIT_SUCCESS;
int Lflag = 0; int Lflag = 0;
int (*fn)(const char *, struct stat *); int (*fn)(const char *, struct stat *);
char *fnname;
ARGBEGIN { ARGBEGIN {
case 'L': case 'L':
@ -41,10 +42,17 @@ main(int argc, char *argv[])
show_stat("<stdin>", &st); show_stat("<stdin>", &st);
} }
if (Lflag) {
fn = stat;
fnname = "stat";
} else {
fn = lstat;
fnname = "lstat";
}
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
fn = Lflag ? stat : lstat;
if (fn(argv[i], &st) == -1) { if (fn(argv[i], &st) == -1) {
fprintf(stderr, "%s %s: %s\n", Lflag ? "stat" : "lstat", fprintf(stderr, "%s %s: %s\n", fnname,
argv[i], strerror(errno)); argv[i], strerror(errno));
ret = EXIT_FAILURE; ret = EXIT_FAILURE;
continue; continue;