[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
+ // If POSIX_CLOSE_RESTART is zero, posix_close shall not return an EINTR
+ // error. On Linux, the descriptor is released immediately, but background
+ // state flush may be interrupted. Map EINTR to EINPROGRESS per POSIX.
+ if (error == EINTR)
+ error = EINPROGRESS;
+#endif
+ libc_errno = error;
+ return -1;
+ }
+
+ if (flag != 0 && flag != POSIX_CLOSE_RESTART) {
----------------
labath wrote:
Then you can also drop one of these.
```suggestion
if (flag != 0) {
```
https://github.com/llvm/llvm-project/pull/240024
More information about the libc-commits
mailing list