[hackers] [ubase] stat: assign fn before loop || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Fri, 14 Feb 2014 15:11:23 +0100

commit 68c3146a9def993741f2e4dab515aa8bfb1fb4e1
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Feb 14 14:48:24 2014 +0100

    stat: assign fn before loop
    
    Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>

diff --git a/stat.c b/stat.c
index 7b55966..93c4991 100644
--- a/stat.c
+++ b/stat.c
_AT_@ -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':
_AT_@ -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
", Lflag ? "stat" : "lstat",
+ fprintf(stderr, "%s %s: %s
", fnname,
                                 argv[i], strerror(errno));
                         ret = EXIT_FAILURE;
                         continue;
Received on Fri Feb 14 2014 - 15:11:23 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 14 2014 - 15:12:29 CET