28 lines
549 B
C
28 lines
549 B
C
|
#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;
|
||
|
}
|