X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/77e7b21f117eecd04bb31257ee68dfc1f425a47e..96cf56ea15a22b8b362aac6c3ab202d2608e9151:/lunaix-os/kernel/demos/dir_read.c?ds=sidebyside diff --git a/lunaix-os/kernel/demos/dir_read.c b/lunaix-os/kernel/demos/dir_read.c index 8c4a344..0d62a79 100644 --- a/lunaix-os/kernel/demos/dir_read.c +++ b/lunaix-os/kernel/demos/dir_read.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include LOG_MODULE("RDDIR") @@ -7,15 +9,24 @@ LOG_MODULE("RDDIR") void _readdir_main() { - int fd = open("/bus/../..", 0); + int fd = open("/dev/./../dev/.", 0); if (fd == -1) { - kprintf(KERROR "fail to open\n"); + kprintf(KERROR "fail to open (%d)\n", geterrno()); return; } + char path[129]; + int len = realpathat(fd, path, 128); + if (len < 0) { + kprintf(KERROR "fail to read (%d)\n", geterrno()); + } else { + path[len] = 0; + kprintf("%s\n", path); + } + struct dirent ent = { .d_offset = 0 }; - while (!readdir(fd, &ent)) { + while (readdir(fd, &ent) == 1) { kprintf(KINFO "%s\n", ent.d_name); }