Luna/apps/src/ls.c

28 lines
549 B
C
Raw Normal View History

#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;
}