[libc-commits] [libc] [llvm] [libc] implement popen/pclose (PR #232846)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Oct 19 02:04:32 PDT 2026


================
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Implementation of the POSIX pclose function for Linux.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/stdio/pclose.h"
+
+#include "hdr/types/FILE.h"
+#include "hdr/types/pid_t.h"
+#include "src/__support/File/linux/popen_file.h"
+#include "src/__support/OSUtil/linux/shell_fork.h"
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, pclose, (::FILE * stream)) {
+  // Passing a stream that was not created by popen is undefined behavior.
+  auto *file = reinterpret_cast<PopenFile *>(stream);
----------------
labath wrote:

add LIBC_CRASH_ON_NULLPTR(stream); ?

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


More information about the libc-commits mailing list