[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:52 PST 2026
================
@@ -0,0 +1,38 @@
+//===-- Linux implementation of 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 "src/unistd/posix_close.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)) {
+#ifdef POSIX_CLOSE_RESTART
+ if (flag != 0 && flag != POSIX_CLOSE_RESTART) {
+#else
+ if (flag != 0) {
+#endif
+ libc_errno = EINVAL;
+ return -1;
----------------
vonosmas wrote:
Quoting POSIX:
```
If flag is invalid, posix_close() may fail with errno set to [EINVAL], but shall otherwise behave as if flag had been 0 and close fd.
```
https://github.com/llvm/llvm-project/pull/240024
More information about the libc-commits
mailing list