diff --git a/kernel b/kernel index 4a84d25..e77df50 160000 --- a/kernel +++ b/kernel @@ -1 +1 @@ -Subproject commit 4a84d25bc821255bd68f59fe93c1f6f5ccd4468c +Subproject commit e77df50caac0c682e4f8cddd05b5b36c4312b922 diff --git a/src/fs.c b/src/fs.c index 02f85ea..e12259b 100644 --- a/src/fs.c +++ b/src/fs.c @@ -216,6 +216,44 @@ static int print_getdents64(const char *path) { return 0; } +static int print_readdir(const char *path) { + fprintf(stderr, "print_readdir(\"%s\")\n", path); + + fprintf(stderr, "opendir(\"%s\")\n", path); + DIR *dir = opendir(path); + if (dir == NULL) { + perror("opendir() failed"); + return -1; + } + + fputc('\n', stderr); + for (;;) { + errno = 0; + // NOLINTNEXTLINE(concurrency-mt-unsafe) + struct dirent *dirent = readdir(dir); + if (dirent == NULL) { + break; + } + + fprintf(stderr, "%s\n", dirent->d_name); + } + if (errno != 0) { + perror("readdir() failed"); + return -1; + } + fputc('\n', stderr); + + fprintf(stderr, "closedir(\"%s\")\n", path); + int closed = closedir(dir); + if (closed == -1) { + perror("closedir() failed"); + return -1; + } + + fputc('\n', stderr); + return 0; +} + int main(void) { #ifdef __hermit__ const char *dir_path = "/my-dir"; @@ -240,6 +278,11 @@ int main(void) { return EXIT_FAILURE; } + int readdir_status = print_readdir(dir_path); + if (readdir_status == -1) { + return EXIT_FAILURE; + } + int unlink_status = unlink_files(dir_path, file_count); if (unlink_status == -1) { return EXIT_FAILURE;