summaryrefslogtreecommitdiffstats
path: root/commands/ls.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-05-10 15:40:23 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-05-11 21:31:36 +0200
commitd173874abbfa6e7d0fc410df787b56f5410b3937 (patch)
tree27902752d25ee0ea074382d0d4aa412ebee01fb3 /commands/ls.c
parenta602bebcf7e42eb8933f224c12cad1c9320e28a1 (diff)
downloadbarebox-d173874abbfa6e7d0fc410df787b56f5410b3937.tar.gz
barebox-d173874abbfa6e7d0fc410df787b56f5410b3937.tar.xz
ls: Fix showing links to directories
With links to directories we have to do some adjustments in the printout. In ls_one we have to use lstat() because we want to show informations about the file or link. When determing if it's a file or directory that we show we have to use stat() instead. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/ls.c')
-rw-r--r--commands/ls.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/commands/ls.c b/commands/ls.c
index 331a4d2015..771477b6e0 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -26,15 +26,21 @@
#include <getopt.h>
#include <stringlist.h>
-static void ls_one(const char *path, const char* fullname, struct stat *s)
+static void ls_one(const char *path, const char* fullname)
{
char modestr[11];
unsigned int namelen = strlen(path);
+ struct stat s;
+ int ret;
+
+ ret = lstat(fullname, &s);
+ if (ret)
+ return;
- mkmodestr(s->st_mode, modestr);
- printf("%s %14llu %*.*s", modestr, s->st_size, namelen, namelen, path);
+ mkmodestr(s.st_mode, modestr);
+ printf("%s %14llu %*.*s", modestr, s.st_size, namelen, namelen, path);
- if (S_ISLNK(s->st_mode)) {
+ if (S_ISLNK(s.st_mode)) {
char realname[PATH_MAX];
memset(realname, 0, PATH_MAX);
@@ -58,14 +64,14 @@ int ls(const char *path, ulong flags)
string_list_init(&sl);
- if (lstat(path, &s))
+ if (stat(path, &s))
return -errno;
if (flags & LS_SHOWARG && s.st_mode & S_IFDIR)
printf("%s:\n", path);
if (!(s.st_mode & S_IFDIR)) {
- ls_one(path, path, &s);
+ ls_one(path, path);
return 0;
}
@@ -89,7 +95,7 @@ int ls(const char *path, ulong flags)
continue;
}
- ls_one(entry->str, tmp, &s);
+ ls_one(entry->str, tmp);
}
}
@@ -162,7 +168,7 @@ static int do_ls(int argc, char *argv[])
/* first pass: all files */
while (o < argc) {
- ret = lstat(argv[o], &s);
+ ret = stat(argv[o], &s);
if (ret) {
printf("%s: %s: %s\n", argv[0],
argv[o], errno_str());
@@ -175,7 +181,7 @@ static int do_ls(int argc, char *argv[])
if (flags & LS_COLUMN)
string_list_add_sorted(&sl, argv[o]);
else
- ls_one(argv[o], argv[o], &s);
+ ls_one(argv[o], argv[o]);
}
o++;
@@ -190,7 +196,7 @@ static int do_ls(int argc, char *argv[])
/* second pass: directories */
while (o < argc) {
- ret = lstat(argv[o], &s);
+ ret = stat(argv[o], &s);
if (ret) {
o++;
exitcode = COMMAND_ERROR;