Skip to content

Commit

Permalink
Support "ls <path>" rather than just "ls" :^)
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Nov 17, 2018
1 parent 95e0f6a commit e440c3f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Userland/ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
#include <LibC/errno.h>
#include <LibC/string.h>

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);
Expand Down

0 comments on commit e440c3f

Please sign in to comment.