diff options
Diffstat (limited to 'commands/ls.c')
-rw-r--r-- | commands/ls.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/commands/ls.c b/commands/ls.c index 6a5475d094..09a20e0a23 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -15,7 +15,7 @@ /* * SIZELEN = strlen(itoa(MAX_LFS_FILESIZE)) + 1; */ -#ifdef CONFIG_CPU_64 +#ifdef CONFIG_64BIT #define SIZELEN 20 #else #define SIZELEN 14 @@ -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; } @@ -75,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); @@ -99,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); @@ -111,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); } @@ -163,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 @@ -196,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"); |