1// RUN: %clang %s -o %t && %run %t 2>&1 | FileCheck %s
2//
3// Older versions of Android do not have certain posix_spawn* functions.
4// UNSUPPORTED: android
5
6#include <assert.h>
7#include <spawn.h>
8#include <stdio.h>
9#include <sys/wait.h>
10
11int main(int argc, char **argv) {
12 if (argc > 1) {
13 // CHECK: SPAWNED
14 // CHECK: SPAWNED
15 printf(format: "SPAWNED\n");
16 return 0;
17 }
18
19 posix_spawnattr_t attr = {0};
20 posix_spawn_file_actions_t file_actions = {0};
21
22 char *const args[] = {
23 argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4",
24 "2", "3", "4", "2", "3", "4", "2", "3", "4", NULL,
25 };
26 char *const env[] = {
27 "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B",
28 "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL,
29 };
30
31 pid_t pid;
32 int s = posix_spawn(pid: &pid, path: argv[0], file_actions: &file_actions, attrp: &attr, argv: args, envp: env);
33 assert(!s);
34
35 waitpid(pid: pid, stat_loc: &s, WUNTRACED | WCONTINUED);
36
37 s = posix_spawnp(pid: &pid, file: argv[0], file_actions: &file_actions, attrp: &attr, argv: args, envp: env);
38 assert(!s);
39
40 waitpid(pid: pid, stat_loc: &s, WUNTRACED | WCONTINUED);
41 return 0;
42}
43

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c