summaryrefslogtreecommitdiffstats
path: root/commands/ls.c
diff options
context:
space:
mode:
authorSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-27 14:14:24 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-27 14:14:24 +0200
commit04f2ec02632028e2442a1264c0686ca7fc4890e7 (patch)
tree3388d6cc1b5d50b5d1b0d7e1cf2b043448f5d42b /commands/ls.c
parent299434c85ef733727ba2d7fd1280a8e421a46f10 (diff)
downloadbarebox-04f2ec02632028e2442a1264c0686ca7fc4890e7.tar.gz
fix usage of normalise_path
Diffstat (limited to 'commands/ls.c')
-rw-r--r--commands/ls.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/commands/ls.c b/commands/ls.c
index d9f26a3..8259264 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -24,6 +24,7 @@
#include <fs.h>
#include <linux/stat.h>
#include <errno.h>
+#include <malloc.h>
#include <getopt.h>
static void ls_one(const char *path, struct stat *s)
@@ -45,10 +46,8 @@ int ls(const char *path, ulong flags)
if (flags & LS_SHOWARG)
printf("%s:\n", path);
- if (stat(path, &s)) {
- perror("stat");
+ if (stat(path, &s))
return errno;
- }
if (!(s.st_mode & S_IFDIR)) {
ls_one(path, &s);
@@ -78,16 +77,20 @@ int ls(const char *path, ulong flags)
}
while ((d = readdir(dir))) {
- sprintf(tmp, "%s/%s", path, d->d_name);
- normalise_path(tmp);
- if (stat(tmp, &s))
- goto out;
+
if (!strcmp(d->d_name, "."))
continue;
if (!strcmp(d->d_name, ".."))
continue;
- if (s.st_mode & S_IFDIR)
- ls(tmp, flags);
+ sprintf(tmp, "%s/%s", path, d->d_name);
+
+ if (stat(tmp, &s))
+ goto out;
+ if (s.st_mode & S_IFDIR) {
+ char *norm = normalise_path(tmp);
+ ls(norm, flags);
+ free(norm);
+ }
}
out:
closedir(dir);