aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Renaud <andre@bluewatersys.com>2012-03-03 18:17:49 -0600
committerAndre Renaud <andre@bluewatersys.com>2012-03-03 18:17:49 -0600
commite8a9df4efb147437fe03e9267b72246a5009d342 (patch)
tree36d77b8466fd54805ee140133a55278f63cc2800
parent84b226df2709887171d8889e961016e6d9bf13e6 (diff)
downloadtoybox-e8a9df4efb147437fe03e9267b72246a5009d342.tar.gz
Add -A to ls
-rw-r--r--toys/ls.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/toys/ls.c b/toys/ls.c
index 9a0c3e27..7610920d 100644
--- a/toys/ls.c
+++ b/toys/ls.c
@@ -6,18 +6,19 @@
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html
-USE_LS(NEWTOY(ls, "nRlF1a", TOYFLAG_BIN))
+USE_LS(NEWTOY(ls, "AnRlF1a", TOYFLAG_BIN))
config LS
bool "ls"
default n
help
- usage: ls [-l] [-F] [-a] [-1] [directory...]
+ usage: ls [-lFaA1] [directory...]
list files
- -F append a character as a file type indicator
- -a list all files
-1 list one file per line
+ -a list all files
+ -A list all files except . and ..
+ -F append a character as a file type indicator
-l show full details for each file
*/
@@ -37,13 +38,20 @@ config LS
#define FLAG_l 8
#define FLAG_R 16
#define FLAG_n 32
+#define FLAG_A 64
static int dir_filter(const struct dirent *d)
{
- /* Skip over the . & .. entries unless -a is given */
- if (!(toys.optflags & FLAG_a))
- if (d->d_name[0] == '.')
+ /* Skip over all '.*' entries, unless -a is given */
+ if (!(toys.optflags & FLAG_a)) {
+ /* -A means show everything except the . & .. entries */
+ if (toys.optflags & FLAG_A) {
+ if (strcmp(d->d_name, ".") == 0 ||
+ strcmp(d->d_name, "..") == 0)
+ return 0;
+ } else if (d->d_name[0] == '.')
return 0;
+ }
return 1;
}