apps: Add a little ls utility that lists the files in /bin

This commit is contained in:
apio 2022-10-23 14:06:11 +02:00
parent 14367f07b5
commit 32db366781
2 changed files with 29 additions and 1 deletions

View File

@ -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
View 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;
}