From e440c3fa87d69d77c6af390d33f535c67c91f8b9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Nov 2018 01:04:00 +0100 Subject: [PATCH] Support "ls " rather than just "ls" :^) --- Userland/ls.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Userland/ls.cpp b/Userland/ls.cpp index fa1f3e71db..fe0f33f4eb 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -4,20 +4,27 @@ #include #include +static int do_dir(const char* path); + int main(int argc, char** argv) { - (void) argc; - (void) argv; - bool colorize = true; + if (argc == 2) { + return do_dir(argv[1]); + } + return do_dir("."); +} - DIR* dirp = opendir("."); +int do_dir(const char* path) +{ + DIR* dirp = opendir(path); if (!dirp) { - perror("opendir failed"); + perror("opendir"); return 1; } + bool colorize = true; char pathbuf[256]; while (auto* de = readdir(dirp)) { - sprintf(pathbuf, "%s", de->d_name); + sprintf(pathbuf, "%s/%s", path, de->d_name); struct stat st; int rc = lstat(pathbuf, &st);