From 04f2ec02632028e2442a1264c0686ca7fc4890e7 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 27 Sep 2007 14:14:24 +0200 Subject: fix usage of normalise_path --- commands/ls.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'commands/ls.c') diff --git a/commands/ls.c b/commands/ls.c index d9f26a3758..82592641b7 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -24,6 +24,7 @@ #include #include #include +#include #include 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); -- cgit v1.2.3