diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-06-02 21:59:15 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-06-10 09:50:46 +0200 |
commit | 7cceef54a045ca8b9b33145b708d843b371718ba (patch) | |
tree | a7583a6eda4cbd3da4a44a284b07d1ab105807d9 /commands/ls.c | |
parent | a7e2fc8d5da3955af8a69dc006e3e8c3cddb921d (diff) | |
download | barebox-7cceef54a045ca8b9b33145b708d843b371718ba.tar.gz barebox-7cceef54a045ca8b9b33145b708d843b371718ba.tar.xz |
commands: ls: explicitly check for directories with S_ISDIR
S_ISDIR(mode) is implemented as (mode & S_IFMT) == S_IFDIR, which
accounts for file modes setting multiple bits. So far, this was not the
case, but upcoming S_IFBLK equals (S_IFCHR | S_IFDIR), which would fail
the existing checks, so prepare for that by fixing them.
No functional change. There are no other instances of this elsewhere in
the code base.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220602195916.9061-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/ls.c')
-rw-r--r-- | commands/ls.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/commands/ls.c b/commands/ls.c index bedf2e1c42..1192aed971 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -63,10 +63,10 @@ int ls(const char *path, ulong flags) if (stat(path, &s)) return -errno; - if (flags & LS_SHOWARG && s.st_mode & S_IFDIR) + if (flags & LS_SHOWARG && S_ISDIR(s.st_mode)) printf("%s:\n", path); - if (!(s.st_mode & S_IFDIR)) { + if (!S_ISDIR(s.st_mode)) { ls_one(path, path); return 0; } @@ -112,7 +112,7 @@ int ls(const char *path, ulong flags) continue; } - if (s.st_mode & S_IFDIR) + if (S_ISDIR(s.st_mode)) ls(tmp, flags); } @@ -171,7 +171,7 @@ static int do_ls(int argc, char *argv[]) continue; } - if (!(s.st_mode & S_IFDIR)) { + if (!S_ISDIR(s.st_mode)) { if (flags & LS_COLUMN) string_list_add_sorted(&sl, argv[o]); else @@ -197,7 +197,7 @@ static int do_ls(int argc, char *argv[]) continue; } - if (s.st_mode & S_IFDIR) { + if (S_ISDIR(s.st_mode)) { ret = ls(argv[o], flags); if (ret) { perror("ls"); |