Skip to content

[llvm-test-suite][tools] Fix not utility to avoid std::system #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tools/not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#include <windows.h>
#endif

#ifdef __APPLE__
#if defined(__unix__) || defined(__APPLE__)
#include <spawn.h>
#include <sys/wait.h>
#include <TargetConditionals.h>
#endif

int main(int argc, char* const* argv) {
Expand Down Expand Up @@ -56,20 +55,22 @@ int main(int argc, char* const* argv) {
return 1;

int result;
#if !defined(TARGET_OS_IPHONE)

#if defined(__unix__) || defined(__APPLE__)
pid_t pid;
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
return EXIT_FAILURE;
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
return EXIT_FAILURE;
#else
std::stringstream ss;
ss << argv[0];
for (int i = 1; i < argc; ++i)
ss << " " << argv[i];
std::string cmd = ss.str();
result = std::system(cmd.c_str());
#else
pid_t pid;
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
return EXIT_FAILURE;
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
return EXIT_FAILURE;
#endif

int retcode = 0;
int signal = 0;

Expand Down