ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit afc831a836d51a3e49a5b5230ce3b815bdb4b63d
parent a7dc139c3585f822384b9b7d24b821ff55f30e2f
Author: sin <sin@2f30.org>
Date:   Mon Aug 12 10:11:55 +0100

Implement -L flag for stat(1)

Diffstat:
stat.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/stat.c b/stat.c @@ -13,7 +13,7 @@ static void show_stat(const char *file, struct stat *st); static void usage(void) { - eprintf("usage: %s filename...\n", argv0); + eprintf("usage: %s [-L] filename...\n", argv0); } int @@ -21,8 +21,13 @@ main(int argc, char *argv[]) { struct stat st; int i, ret = 0; + int Lflag = 0; + int (*fn)(const char *, struct stat *); ARGBEGIN { + case 'L': + Lflag = 1; + break; default: usage(); } ARGEND; @@ -34,8 +39,10 @@ main(int argc, char *argv[]) } for (i = 0; i < argc; i++) { - if (stat(argv[i], &st) == -1) { - fprintf(stderr, "stat %s: ", argv[i]); + fn = Lflag ? stat : lstat; + if (fn(argv[i], &st) == -1) { + fprintf(stderr, "%s %s: ", Lflag ? "stat" : "lstat", + argv[i]); perror(NULL); ret = 1; continue;