2023-03-29 16:27:02 +00:00
|
|
|
#include <os/ArgumentParser.h>
|
|
|
|
|
2023-03-28 23:07:58 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2023-03-29 16:27:02 +00:00
|
|
|
StringView pathname;
|
|
|
|
|
|
|
|
ArgumentParser parser;
|
|
|
|
parser.add_positional_argument(pathname, "directory", false, "/");
|
|
|
|
parser.parse(argc, argv);
|
2023-03-28 23:07:58 +00:00
|
|
|
|
2023-03-29 16:27:02 +00:00
|
|
|
DIR* dp = opendir(pathname.chars());
|
2023-03-28 23:07:58 +00:00
|
|
|
if (!dp)
|
|
|
|
{
|
|
|
|
perror("opendir");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int first_ent = 1;
|
|
|
|
do {
|
|
|
|
struct dirent* ent = readdir(dp);
|
|
|
|
if (!ent) break;
|
|
|
|
printf(first_ent ? "%s" : " %s", ent->d_name);
|
|
|
|
first_ent = 0;
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
closedir(dp);
|
|
|
|
return 0;
|
|
|
|
}
|