This commit is contained in:
parent
3e30f0a88c
commit
7b0b3dabc4
@ -11,3 +11,4 @@ luna_app(cat.c cat)
|
||||
luna_app(edit.c edit)
|
||||
luna_app(sh.c sh)
|
||||
luna_app(date.c date)
|
||||
luna_app(ls.c ls)
|
||||
|
32
apps/ls.c
Normal file
32
apps/ls.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* pathname;
|
||||
if (argc == 1) pathname = "/";
|
||||
else
|
||||
pathname = argv[1];
|
||||
|
||||
DIR* dp = opendir(pathname);
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user