diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt index dc700941c667c..c36a623701e5c 100644 --- a/libc/config/linux/riscv64/entrypoints.txt +++ b/libc/config/linux/riscv64/entrypoints.txt @@ -341,6 +341,12 @@ if(LLVM_LIBC_FULL_BUILD) # assert.h entrypoints libc.src.assert.__assert_fail + # dirent.h entrypoints + libc.src.dirent.closedir + libc.src.dirent.dirfd + libc.src.dirent.opendir + libc.src.dirent.readdir + # network.h entrypoints libc.src.network.htonl libc.src.network.htons diff --git a/libc/config/linux/riscv64/headers.txt b/libc/config/linux/riscv64/headers.txt index 2d8ed5001c143..aaa75a9dd08cb 100644 --- a/libc/config/linux/riscv64/headers.txt +++ b/libc/config/linux/riscv64/headers.txt @@ -1,6 +1,7 @@ set(TARGET_PUBLIC_HEADERS libc.include.assert libc.include.ctype + libc.include.dirent libc.include.errno libc.include.fcntl libc.include.fenv diff --git a/libc/include/llvm-libc-types/struct_dirent.h b/libc/include/llvm-libc-types/struct_dirent.h index 44bda4caae452..fde3f8ce47980 100644 --- a/libc/include/llvm-libc-types/struct_dirent.h +++ b/libc/include/llvm-libc-types/struct_dirent.h @@ -18,6 +18,7 @@ struct dirent { off_t d_off; unsigned short d_reclen; #endif + unsigned char d_type; // The user code should use strlen to determine actual the size of d_name. // Likewise, it is incorrect and prohibited by the POSIX standard to detemine // the size of struct dirent type using sizeof. The size should be got using diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt index 2d94c2f30a49d..79de9250c642b 100644 --- a/libc/src/__support/File/CMakeLists.txt +++ b/libc/src/__support/File/CMakeLists.txt @@ -11,7 +11,6 @@ add_object_library( HDRS file.h DEPENDS - libc.src.__support.CPP.new libc.src.__support.CPP.span libc.src.__support.threads.mutex @@ -37,7 +36,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}_file.cpp) ${LIBC_TARGET_OS}_file.cpp DEPENDS .file - libc.include.fcntl libc.include.stdio libc.include.sys_syscall diff --git a/libc/src/__support/File/dir.cpp b/libc/src/__support/File/dir.cpp index 70f550ffab72d..e632c9293d617 100644 --- a/libc/src/__support/File/dir.cpp +++ b/libc/src/__support/File/dir.cpp @@ -12,8 +12,6 @@ #include "src/__support/error_or.h" #include "src/errno/libc_errno.h" // For error macros -#include - namespace __llvm_libc { ErrorOr Dir::open(const char *path) { diff --git a/libc/src/__support/File/linux_dir.cpp b/libc/src/__support/File/linux_dir.cpp index 86aaaae907d22..aae565ffb337a 100644 --- a/libc/src/__support/File/linux_dir.cpp +++ b/libc/src/__support/File/linux_dir.cpp @@ -34,8 +34,13 @@ ErrorOr platform_opendir(const char *name) { } ErrorOr platform_fetch_dirents(int fd, cpp::span buffer) { - long size = - __llvm_libc::syscall_impl(SYS_getdents, fd, buffer.data(), buffer.size()); +#ifdef SYS_getdents64 + long size = __llvm_libc::syscall_impl(SYS_getdents64, fd, buffer.data(), + buffer.size()); +#else +#error "getdents64 syscalls not available to perform a fetch dirents operation." +#endif + if (size < 0) { return __llvm_libc::Error(static_cast(-size)); }