commit 68c3146a9def993741f2e4dab515aa8bfb1fb4e1
parent 780fd613ebbdb59f183ec93778ee0c31d6bcede3
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 14 Feb 2014 14:48:24 +0100
stat: assign fn before loop
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/stat.c b/stat.c
@@ -26,6 +26,7 @@ main(int argc, char *argv[])
int i, ret = EXIT_SUCCESS;
int Lflag = 0;
int (*fn)(const char *, struct stat *);
+ char *fnname;
ARGBEGIN {
case 'L':
@@ -41,10 +42,17 @@ main(int argc, char *argv[])
show_stat("<stdin>", &st);
}
+ if (Lflag) {
+ fn = stat;
+ fnname = "stat";
+ } else {
+ fn = lstat;
+ fnname = "lstat";
+ }
+
for (i = 0; i < argc; i++) {
- fn = Lflag ? stat : lstat;
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));
ret = EXIT_FAILURE;
continue;