summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorfaissaloo <faissaloo@gmail.com>2019-05-27 13:30:09 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-05-27 14:53:16 +0200
commit4c410f3de652cae8085d8f88dbbf7759cc0f7351 (patch)
tree5a7fa204909acf3632cf6d7dcc5199a3efcb2ffc /Userland
parent776a359a17462405fdf89adba7eeada1170e884a (diff)
downloadserenity-4c410f3de652cae8085d8f88dbbf7759cc0f7351.zip
Ls: Support multiple files
Diffstat (limited to 'Userland')
-rw-r--r--Userland/ls.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/Userland/ls.cpp b/Userland/ls.cpp
index 05d59c2e9e..02a538b0bc 100644
--- a/Userland/ls.cpp
+++ b/Userland/ls.cpp
@@ -38,21 +38,37 @@ int main(int argc, char** argv)
flag_show_inode = true;
break;
default:
- fprintf(stderr, "usage: ls [-%s] [path]\n", valid_option_characters);
+ fprintf(stderr, "usage: ls [-%s] [paths...]\n", valid_option_characters);
return 1;
}
}
- const char* path;
-
- if (optind >= argc)
- path = ".";
- else
- path = argv[optind];
-
- if (flag_long)
- return do_dir(path);
- return do_dir_short(path);
+ int status;
+ if (optind >= argc) {
+ if (flag_long) {
+ status = do_dir(".");
+ } else {
+ status = do_dir_short(".");
+ }
+ return status;
+ } else {
+ bool show_names = !(optind+1 >= argc);
+
+ for (; optind < argc; optind++) {
+ if (show_names) {
+ printf("%s:\n", argv[optind]);
+ }
+ if (flag_long) {
+ status = do_dir(argv[optind]);
+ } else {
+ status = do_dir_short(argv[optind]);
+ }
+ if (status != 0) {
+ return status;
+ }
+ }
+ }
+ return 0;
}
void get_geometry(int& rows, int& columns)