summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/ls.c24
-rw-r--r--include/fs.h1
2 files changed, 22 insertions, 3 deletions
diff --git a/commands/ls.c b/commands/ls.c
index 276b5e2893..b9263e645a 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -27,6 +27,7 @@
#include <errno.h>
#include <malloc.h>
#include <getopt.h>
+#include <stringlist.h>
static void ls_one(const char *path, struct stat *s)
{
@@ -43,6 +44,9 @@ int ls(const char *path, ulong flags)
struct dirent *d;
char tmp[PATH_MAX];
struct stat s;
+ struct string_list sl;
+
+ string_list_init(&sl);
if (flags & LS_SHOWARG)
printf("%s:\n", path);
@@ -63,11 +67,19 @@ int ls(const char *path, ulong flags)
sprintf(tmp, "%s/%s", path, d->d_name);
if (stat(tmp, &s))
goto out;
- ls_one(d->d_name, &s);
+ if (flags & LS_COLUMN)
+ string_list_add(&sl, d->d_name);
+ else
+ ls_one(d->d_name, &s);
}
closedir(dir);
+ if (flags & LS_COLUMN) {
+ string_list_print_by_column(&sl);
+ string_list_free(&sl);
+ }
+
if (!(flags & LS_RECURSIVE))
return 0;
@@ -102,15 +114,21 @@ out:
static int do_ls (cmd_tbl_t *cmdtp, int argc, char *argv[])
{
int ret, opt;
- ulong flags = 0;
+ ulong flags = LS_COLUMN;
getopt_reset();
- while((opt = getopt(argc, argv, "R")) > 0) {
+ while((opt = getopt(argc, argv, "RCl")) > 0) {
switch(opt) {
case 'R':
flags |= LS_RECURSIVE | LS_SHOWARG;
break;
+ case 'C':
+ flags |= LS_COLUMN;
+ break;
+ case 'l':
+ flags &= ~LS_COLUMN;
+ break;
}
}
diff --git a/include/fs.h b/include/fs.h
index 2785683e67..31243f399f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -134,6 +134,7 @@ void *memmap(int fd, int flags);
#define LS_RECURSIVE 1
#define LS_SHOWARG 2
+#define LS_COLUMN 4
int ls(const char *path, ulong flags);
char *mkmodestr(unsigned long mode, char *str);