mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
these functions are specified to fail with EBADF on negative fd arguments. apart from close, they are also specified to fail if the value exceeds OPEN_MAX, but as written it is not clear that this imposes any requirement when OPEN_MAX is not defined, and it's undesirable to impose a dynamic limit (via setrlimit) here since the limit at the time of posix_spawn may be different from the limit at the time of setting up the file actions. this may require revisiting later.
21 lines
548 B
C
21 lines
548 B
C
#include <spawn.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include "fdop.h"
|
|
|
|
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
|
|
{
|
|
if (fd < 0) return EBADF;
|
|
struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
|
|
if (!op) return ENOMEM;
|
|
op->cmd = FDOP_OPEN;
|
|
op->fd = fd;
|
|
op->oflag = flags;
|
|
op->mode = mode;
|
|
strcpy(op->path, path);
|
|
if ((op->next = fa->__actions)) op->next->prev = op;
|
|
op->prev = 0;
|
|
fa->__actions = op;
|
|
return 0;
|
|
}
|