[libc-commits] [libc] [libc] Implement fexecve in unistd (PR #231230)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Tue Oct 13 02:01:38 PDT 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
+/// Unittests for fexecve.
+///
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/fcntl_macros.h"
+#include "hdr/sys_stat_macros.h"
+#include "src/fcntl/open.h"
+#include "src/unistd/close.h"
+#include "src/unistd/fexecve.h"
+#include "src/unistd/unlink.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LlvmLibcFexecveTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcFexecveTest, BadFd) {
+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+ char *const argv[] = {nullptr};
+ char *const envp[] = {nullptr};
+ ASSERT_THAT(LIBC_NAMESPACE::fexecve(-1, argv, envp), Fails(EBADF));
+}
+
+TEST_F(LlvmLibcFexecveTest, ClosedFd) {
----------------
labath wrote:
To the kernel, and to our own code a "closed" FD looks the same as an invalid FD, so I don't think this is necessary. What we could use is a test for the success case. You can model this on test/integration/src/unistd/execve_test.cpp (note the "integration" tests use a slightly different infrastructure).
https://github.com/llvm/llvm-project/pull/231230
More information about the libc-commits
mailing list