Skip to content

Commit 3216058

Browse files
authored
[llvm-test-suite][tools] Fix not utility to avoid std::system (#142)
* [llvm-test-suite][tools] Fix not utility to avoid std::system Avoid using std::system on Posix platforms when possible. std::system is now only on non-Posix platforms. When available, posix_spawn is preferred.
1 parent 6afc89e commit 3216058

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tools/not.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
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-
#include <TargetConditionals.h>
3130
#endif
3231

3332
int main(int argc, char* const* argv) {
@@ -56,20 +55,22 @@ int main(int argc, char* const* argv) {
5655
return 1;
5756

5857
int result;
59-
#if !defined(TARGET_OS_IPHONE)
58+
59+
#if defined(__unix__) || defined(__APPLE__)
60+
pid_t pid;
61+
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
62+
return EXIT_FAILURE;
63+
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
64+
return EXIT_FAILURE;
65+
#else
6066
std::stringstream ss;
6167
ss << argv[0];
6268
for (int i = 1; i < argc; ++i)
6369
ss << " " << argv[i];
6470
std::string cmd = ss.str();
6571
result = std::system(cmd.c_str());
66-
#else
67-
pid_t pid;
68-
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
69-
return EXIT_FAILURE;
70-
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
71-
return EXIT_FAILURE;
7272
#endif
73+
7374
int retcode = 0;
7475
int signal = 0;
7576

0 commit comments

Comments
 (0)