[libc-commits] [libc] [libc] Never consider an fd being 0 as an error when opening (PR #176581)

via libc-commits libc-commits at lists.llvm.org
Sun Jan 18 21:36:29 PST 2026


https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/176581

>From 3b2ef694a3870927f17abf34c592e5563d573592 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sat, 17 Jan 2026 12:48:30 -0500
Subject: [PATCH] [libc] Never consider an fd being 0 as an error when opening

This is not semantically correct, as we can get 0 when calling open.
---
 libc/src/spawn/linux/posix_spawn.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/spawn/linux/posix_spawn.cpp b/libc/src/spawn/linux/posix_spawn.cpp
index fe82ba260148a..f05815805dc05 100644
--- a/libc/src/spawn/linux/posix_spawn.cpp
+++ b/libc/src/spawn/linux/posix_spawn.cpp
@@ -44,7 +44,7 @@ cpp::optional<int> open(const char *path, int oflags, mode_t mode) {
   int fd = LIBC_NAMESPACE::syscall_impl<int>(SYS_openat, AT_FDCWD, path, oflags,
                                              mode);
 #endif
-  if (fd > 0)
+  if (fd >= 0)
     return fd;
   // The open function is called as part of the child process' preparatory
   // steps. If an open fails, the child process just exits. So, unlike



More information about the libc-commits mailing list