5e2c86d9b12e93da3472be052cce0b1b6bd57a9c
[musl] / src / process / posix_spawn_file_actions_addopen.c
1 #include <spawn.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include "fdop.h"
6
7 int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *fa, int fd, const char *path, int flags, mode_t mode)
8 {
9         struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
10         if (!op) return ENOMEM;
11         op->cmd = FDOP_OPEN;
12         op->fd = fd;
13         op->oflag = flags;
14         op->mode = mode;
15         strcpy(op->path, path);
16         op->next = fa->__actions;
17         fa->__actions = op;
18         return 0;
19 }