summaryrefslogtreecommitdiff
path: root/coreutils/ls.c
diff options
context:
space:
mode:
authorEric Andersen2000-06-07 17:28:53 +0000
committerEric Andersen2000-06-07 17:28:53 +0000
commita42982e8f569417e93bc3b47c501cbe83a5bfade (patch)
treea28be75735aa78f38cf8464f874857fd0132c664 /coreutils/ls.c
parent1f6262b8e2b4225a028b016fed4a3a9ee717b540 (diff)
downloadbusybox-a42982e8f569417e93bc3b47c501cbe83a5bfade.zip
busybox-a42982e8f569417e93bc3b47c501cbe83a5bfade.tar.gz
* Fixed 'swapon -a' and 'swapoff -a', which were broken.
* Fixed 'mount -a' so it works as expected. * Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE) -Erik
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r--coreutils/ls.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 6ab11c4..0b1aa62 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -86,8 +86,9 @@
#define DISP_DOT 8 /* show . and .. */
#define DISP_NUMERIC 16 /* numeric uid and gid */
#define DISP_FULLTIME 32 /* show extended time display */
-#define DIR_NOLIST 64 /* show directory as itself, not contents */
+#define DIR_NOLIST 64 /* show directory as itself, not contents */
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
+#define DISP_RECURSIVE 256 /* Do a recursive listing */
#ifndef MAJOR
#define MAJOR(dev) (((dev)>>8)&0xff)
@@ -449,6 +450,9 @@ static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+ "R"
+#endif
"] [filenames...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nList directory contents\n\n"
@@ -477,9 +481,24 @@ static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_FILETYPES
"\t-F\tappend indicator (one of */=@|) to entries\n"
#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+ "\t-R\tlist subdirectories recursively\n"
+#endif
#endif
;
+
+#ifdef BB_FEATURE_LS_RECURSIVE
+static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
+{
+ int i;
+ fprintf(stdout, "\n%s:\n", fileName);
+ i = list_item(fileName);
+ newline();
+ return (i);
+}
+#endif
+
extern int ls_main(int argc, char **argv)
{
int argi = 1, i;
@@ -544,6 +563,11 @@ extern int ls_main(int argc, char **argv)
opts |= DISP_FULLTIME;
break;
#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+ case 'R':
+ opts |= DISP_RECURSIVE;
+ break;
+#endif
default:
goto print_usage_message;
}
@@ -570,12 +594,25 @@ extern int ls_main(int argc, char **argv)
#endif
/* process files specified, or current directory if none */
- i = 0;
- if (argi == argc)
- i = list_item(".");
- while (argi < argc)
- i |= list_item(argv[argi++]);
- newline();
+#ifdef BB_FEATURE_LS_RECURSIVE
+ if (opts & DISP_RECURSIVE) {
+ i = 0;
+ if (argi == argc) {
+ i = recursiveAction(".", TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+ }
+ while (argi < argc) {
+ i |= recursiveAction(argv[argi++], TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+ }
+ } else
+#endif
+ {
+ i = 0;
+ if (argi == argc)
+ i = list_item(".");
+ while (argi < argc)
+ i |= list_item(argv[argi++]);
+ newline();
+ }
exit(i);
print_usage_message: