apps: Add a little ls utility that lists the files in /bin
This commit is contained in:
parent
14367f07b5
commit
32db366781
@ -1,4 +1,4 @@
|
||||
APPS := init sym sh crash uname uptime hello ps
|
||||
APPS := init sym sh crash uname uptime hello ps ls
|
||||
|
||||
APPS_DIR := $(LUNA_ROOT)/apps
|
||||
APPS_SRC := $(APPS_DIR)/src
|
||||
|
28
apps/src/ls.c
Normal file
28
apps/src/ls.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <fcntl.h>
|
||||
#include <luna/dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int dirfd = open("/bin", O_RDONLY);
|
||||
if (dirfd < 0)
|
||||
{
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
struct luna_dirent dirent[5];
|
||||
ssize_t nread;
|
||||
do {
|
||||
nread = getdents(dirfd, dirent, 5);
|
||||
if (nread < 0)
|
||||
{
|
||||
perror("getdents");
|
||||
return 1;
|
||||
}
|
||||
for (int i = 0; i < nread; i++) { printf("%s\n", dirent[i].name); }
|
||||
} while (nread == 5);
|
||||
|
||||
close(dirfd);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user