What posix_spawn does is something like this:
posix_spawn() {
...
pid_t pid = fork();
if (pid == 0) {
...
} else if (pid > 0) {
...
if (...) {
...
return ernno_from_child;
}
...
} else {
return errno;
}
...
}
I’m just pointing out that you’re still using errno, you’ve just hidden it behind a function. All of your syscalls are still getting their results stored in errno. It’s just fork() / exec() with some extra sauce, not a syscall in itself.
I’m not trying to argue, I’m just pointing out that this is just a wrapper function on Linux anyway, and if you want to find an example of a different way to report errors from the kernel, it’s not posix_spawn().