对于函数posix_spawn
,它的原型是:
int posix_spawn(pid_t *restrict pid, const char *restrict path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict], char *const envp[restrict]);
值得注意的是,
argv
参数指向一个char *
指针数组(即可变字符指针)。此外,文档似乎没有给出任何保证数据不会被写入。我的问题是:是否有任何保证可以传递字符串字面值?还是我们冒着段错误的风险?
示例代码:
char *v[] = { "foo.exe", "bar", NULL };
posix_spawn( NULL, "foo.exe", NULL, NULL, v, NULL );
\0
的情况下。 - Petr Skocik