[hackers] [ubase] stat: declare initial functions to use at the top || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Fri, 04 Apr 2014 21:09:14 +0200

commit 139522b45e499b58b32e100777af701e75c895f2
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Apr 4 17:05:16 2014 +0200

    stat: declare initial functions to use at the top
    
    remove Lflag. this will be more clear for terse format later on aswell.
    
    Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>

diff --git a/stat.c b/stat.c
index 93c4991..a4e4a67 100644
--- a/stat.c
+++ b/stat.c
_AT_@ -24,13 +24,14 @@ main(int argc, char *argv[])
 {
         struct stat st;
         int i, ret = EXIT_SUCCESS;
- int Lflag = 0;
- int (*fn)(const char *, struct stat *);
- char *fnname;
+ int (*fn)(const char *, struct stat *) = lstat;
+ char *fnname = "lstat";
+ void (*showstat)(const char *, struct stat *) = show_stat;
 
         ARGBEGIN {
         case 'L':
- Lflag = 1;
+ fn = stat;
+ fnname = "stat";
                 break;
         default:
                 usage();
_AT_@ -42,14 +43,6 @@ 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++) {
                 if (fn(argv[i], &st) == -1) {
                         fprintf(stderr, "%s %s: %s
", fnname,
_AT_@ -57,7 +50,7 @@ main(int argc, char *argv[])
                         ret = EXIT_FAILURE;
                         continue;
                 }
- show_stat(argv[i], &st);
+ showstat(argv[i], &st);
         }
 
         return ret;
Received on Fri Apr 04 2014 - 21:09:14 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 04 2014 - 21:12:19 CEST