Support "ls <path>" rather than just "ls" :^)

This commit is contained in:
Andreas Kling 2018-11-17 01:04:00 +01:00
parent 95e0f6ad82
commit e440c3fa87
Notes: sideshowbarker 2024-07-19 16:09:55 +09:00

View file

@ -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);