X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/77e7b21f117eecd04bb31257ee68dfc1f425a47e..d8d001a6664b88b66524989589fcd809de6d3a92:/lunaix-os/kernel/demos/dir_read.c diff --git a/lunaix-os/kernel/demos/dir_read.c b/lunaix-os/kernel/demos/dir_read.c index 8c4a344..caa88cc 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,12 +9,21 @@ 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)) {