[libc-commits] [libc] [libc] Implement posix_close in unistd (PR #240024)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 02:26:48 PST 2026


================
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Linux implementation of posix_close.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/posix_close.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/unistd_macros.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, posix_close, (int fd, int flag)) {
+  auto result = linux_syscalls::close(fd);
+
+  if (!result.has_value()) {
+    int error = result.error();
+#if POSIX_CLOSE_RESTART == 0
----------------
labath wrote:

If you want to check this, I'd do it via a static_assert -- this file is linux-specific, and POSIX_CLOSE_RESTART!=0 is not a valid configuration for linux (it implies EINTR leaves the FD open, which just isn't true on linux).

https://github.com/llvm/llvm-project/pull/240024


More information about the libc-commits mailing list