diff options
Diffstat (limited to 'commands/ls.c')
-rw-r--r-- | commands/ls.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/commands/ls.c b/commands/ls.c index e5e37d75c5..09a20e0a23 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -1,21 +1,7 @@ -/* - * ls.c - list files and directories - * - * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: © 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + +/* ls.c - list files and directories */ #include <common.h> #include <command.h> @@ -29,7 +15,7 @@ /* * SIZELEN = strlen(itoa(MAX_LFS_FILESIZE)) + 1; */ -#ifdef CONFIG_CPU_64 +#ifdef CONFIG_64BIT #define SIZELEN 20 #else #define SIZELEN 14 @@ -77,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; } @@ -89,8 +75,13 @@ int ls(const char *path, ulong flags) if (!dir) return -errno; - while ((d = readdir(dir))) + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".")) + continue; + if (!strcmp(d->d_name, "..")) + continue; string_list_add_sorted(&sl, d->d_name); + } closedir(dir); @@ -113,10 +104,6 @@ int ls(const char *path, ulong flags) goto out; string_list_for_each_entry(entry, &sl) { - if (!strcmp(entry->str, ".")) - continue; - if (!strcmp(entry->str, "..")) - continue; sprintf(tmp, "%s/%s", path, entry->str); ret = lstat(tmp, &s); @@ -125,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); } @@ -177,14 +164,13 @@ static int do_ls(int argc, char *argv[]) while (o < argc) { ret = stat(argv[o], &s); if (ret) { - printf("%s: %s: %s\n", argv[0], - argv[o], errno_str()); + printf("%s: %s: %m\n", argv[0], argv[o]); o++; exitcode = COMMAND_ERROR; 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 @@ -210,7 +196,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"); |