github.com/afumu/libc@v0.0.6/musl/src/process/posix_spawn_file_actions_addopen.c (about)

     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 *restrict fa, int fd, const char *restrict 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  	if ((op->next = fa->__actions)) op->next->prev = op;
    17  	op->prev = 0;
    18  	fa->__actions = op;
    19  	return 0;
    20  }