posix_spawn_file_actions_addopen.c 548 B

123456789101112131415161718192021
  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. if (fd < 0) return EBADF;
  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. }