1
0

posix_spawn_file_actions_addopen.c 521 B

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