Skip to content

Commit 1e206b6

Browse files
committed
[llvm-test-suite][tools] Fix not utility to avoid std::system
Avoid using std::system on Unix systems. Some systems such as Ubuntu return a different error code from calls to std::system. Use posix_spawn to avoid having to special case these. std::system is now only used on Windows.
1 parent a73e05c commit 1e206b6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/not.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
#include <windows.h>
2525
#endif
2626

27-
#ifdef __APPLE__
27+
#if defined(__unix__) || defined(__APPLE__)
2828
#include <spawn.h>
2929
#include <sys/wait.h>
30+
#endif
31+
32+
#ifdef __APPLE__
3033
#include <TargetConditionals.h>
3134
#endif
3235

@@ -56,20 +59,23 @@ int main(int argc, char* const* argv) {
5659
return 1;
5760

5861
int result;
59-
#if !defined(TARGET_OS_IPHONE)
62+
#ifdef _WIN32
6063
std::stringstream ss;
6164
ss << argv[0];
6265
for (int i = 1; i < argc; ++i)
6366
ss << " " << argv[i];
6467
std::string cmd = ss.str();
6568
result = std::system(cmd.c_str());
66-
#else
69+
#elif defined(__unix__) || defined(__APPLE__)
6770
pid_t pid;
6871
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
6972
return EXIT_FAILURE;
7073
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
7174
return EXIT_FAILURE;
75+
#else
76+
#error "Unsupported system"
7277
#endif
78+
7379
int retcode = 0;
7480
int signal = 0;
7581

0 commit comments

Comments
 (0)