[libc-commits] [libc] [libc] Implement fdopendir (PR #206590)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Jun 30 10:56:58 PDT 2026
================
@@ -0,0 +1,113 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unit tests for the POSIX fdopendir function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/types/DIR.h"
+#include "hdr/types/struct_dirent.h"
+#include "src/dirent/closedir.h"
+#include "src/dirent/dirfd.h"
+#include "src/dirent/fdopendir.h"
+#include "src/dirent/readdir.h"
+#include "src/fcntl/fcntl.h"
+#include "src/fcntl/open.h"
+#include "src/unistd/close.h"
+
+#include "src/__support/CPP/string_view.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/fcntl_macros.h"
+
+using LlvmLibcFdopendirTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+
+TEST_F(LlvmLibcFdopendirTest, SuccessCase) {
+ int fd = LIBC_NAMESPACE::open("testdata", O_RDONLY | O_DIRECTORY);
+ ASSERT_GT(fd, 0);
+ ASSERT_ERRNO_SUCCESS();
+
+ DIR *dir = LIBC_NAMESPACE::fdopendir(fd);
+ ASSERT_TRUE(dir != nullptr);
+ ASSERT_ERRNO_SUCCESS();
+
+ struct dirent *file1 = nullptr, *file2 = nullptr;
+ while (true) {
+ struct dirent *d = LIBC_NAMESPACE::readdir(dir);
+ if (d == nullptr)
+ break;
+ if (LIBC_NAMESPACE::cpp::string_view(&d->d_name[0]) == "file1.txt")
----------------
michaelrj-google wrote:
wasn't necessary, simplified.
https://github.com/llvm/llvm-project/pull/206590
More information about the libc-commits
mailing list