summaryrefslogtreecommitdiffstats
path: root/commands/ls.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2008-03-11 21:41:56 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2008-03-11 21:41:56 +0100
commitce172e152e5918b08c6f91da6782eb214c285418 (patch)
treedc1d778568f011b8d8e15cbf35d22475117f7dae /commands/ls.c
parentf5a9246875d97f836a20a05b083ffb5f2e475a2f (diff)
downloadbarebox-ce172e152e5918b08c6f91da6782eb214c285418.tar.gz
add ls -c and -l
Diffstat (limited to 'commands/ls.c')
-rw-r--r--commands/ls.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/commands/ls.c b/commands/ls.c
index 276b5e2..b9263e6 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;
}
}