[libc-commits] [libc] [libc] Implement posix_close in unistd (PR #240024)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Sun Nov 8 19:23:53 PST 2026
================
@@ -0,0 +1,62 @@
+//===-- Unittests for posix_close -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/unistd_macros.h"
+#include "src/unistd/close.h"
+#include "src/unistd/pipe.h"
+#include "src/unistd/posix_close.h"
+#include "src/unistd/read.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+using LlvmLibcPosixCloseTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcPosixCloseTest, InvalidFlag) {
+ // Invalid flag should fail with EINVAL.
+ EXPECT_THAT(LIBC_NAMESPACE::posix_close(-1, ~0), Fails<int>(EINVAL));
+ EXPECT_THAT(LIBC_NAMESPACE::posix_close(-1, 0x1234), Fails<int>(EINVAL));
+}
+
+TEST_F(LlvmLibcPosixCloseTest, InvalidFd) {
+ // Valid flag (0) with invalid fd should fail with EBADF.
+ EXPECT_THAT(LIBC_NAMESPACE::posix_close(-1, 0), Fails<int>(EBADF));
+#ifdef POSIX_CLOSE_RESTART
----------------
vonosmas wrote:
We should assume it's always available (see above).
https://github.com/llvm/llvm-project/pull/240024
More information about the libc-commits
mailing list