[libc-commits] [libc] [libc] Implement execvpe in unistd (PR #234071)
Aman Maurya via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 10:48:46 PDT 2026
================
@@ -0,0 +1,191 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Integration tests for execvpe
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/setenv.h"
+#include "src/sys/wait/waitpid.h"
+#include "src/unistd/_exit.h"
+#include "src/unistd/execvpe.h"
+#include "src/unistd/fork.h"
+
+#include "hdr/signal_macros.h"
+#include "hdr/sys_wait_macros.h"
+#include "test/IntegrationTest/test.h"
+
+#include <errno.h>
+
+void fork_and_execvpe_slash_path() {
+ pid_t pid = LIBC_NAMESPACE::fork();
+ if (pid == 0) {
+ const char *path = "./libc_execv_test_normal_exit";
+ char *const argv[] = {
+ const_cast<char *>("execv_test_normal_exit"),
+ nullptr,
+ };
+ char *const envp[] = {
+ const_cast<char *>("EXECV_TEST=PASS"),
+ nullptr,
+ };
+ LIBC_NAMESPACE::execvpe(path, argv, envp);
+ LIBC_NAMESPACE::_exit(errno);
+ }
+ ASSERT_TRUE(pid > 0);
+ int status;
+ pid_t cpid = LIBC_NAMESPACE::waitpid(pid, &status, 0);
+ ASSERT_TRUE(cpid > 0);
+ ASSERT_EQ(cpid, pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+}
+
+void fork_and_execvpe_path_search() {
+ pid_t pid = LIBC_NAMESPACE::fork();
+ if (pid == 0) {
+ ASSERT_EQ(LIBC_NAMESPACE::setenv(
+ "PATH", "/nonexistent_dir_for_execvp_test:testdata", 1),
+ 0);
+ const char *file = "libc_execvp_test_normal_exit";
+ char *const argv[] = {
+ const_cast<char *>("execvp_test_normal_exit"),
+ nullptr,
+ };
+ char *const envp[] = {
+ const_cast<char *>("EXECV_TEST=PASS"),
+ nullptr,
+ };
+ LIBC_NAMESPACE::execvpe(file, argv, envp);
+ LIBC_NAMESPACE::_exit(errno);
+ }
+ ASSERT_TRUE(pid > 0);
+ int status;
+ pid_t cpid = LIBC_NAMESPACE::waitpid(pid, &status, 0);
+ ASSERT_TRUE(cpid > 0);
+ ASSERT_EQ(cpid, pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+}
+
+// POSIX.1-2024 mandates that execvpe() searches for the program using the
----------------
amanmaurya92 wrote:
ohh, yeah. Changed it now
https://github.com/llvm/llvm-project/pull/234071
More information about the libc-commits
mailing list