Home | History | Annotate | Download | only in libiberty

Lines Matching refs:old_fd

398 /* Subroutine of pex_unix_exec_child.  Move OLD_FD to a new file descriptor
400 saved copy to be close-on-exec. Move CHILD_FD into OLD_FD. If CHILD_FD
401 is -1, OLD_FD is to be closed. Return -1 on error. */
404 save_and_install_fd(int *pnew_fd, int *pflags, int old_fd, int child_fd)
408 flags = fcntl (old_fd, F_GETFD);
410 /* If we could not retrieve the flags, then OLD_FD was not open. */
414 if (child_fd >= 0 && dup2 (child_fd, old_fd) < 0)
417 /* If we wish to close OLD_FD, just mark it CLOEXEC. */
420 new_fd = old_fd;
421 if ((flags & FD_CLOEXEC) == 0 && fcntl (old_fd, F_SETFD, FD_CLOEXEC) < 0)
424 /* Otherwise we need to save a copy of OLD_FD before installing CHILD_FD. */
428 new_fd = fcntl (old_fd, F_DUPFD_CLOEXEC, 3);
434 new_fd = fcntl (old_fd, F_DUPFD, 3);
440 if (dup2 (child_fd, old_fd) < 0)
447 else if (new_fd != old_fd)
453 /* Subroutine of pex_unix_exec_child. Move SAVE_FD back to OLD_FD
454 restoring FLAGS. If SAVE_FD < 0, OLD_FD is to be closed. */
457 restore_fd(int old_fd, int save_fd, int flags)
462 return close (old_fd);
464 /* For SAVE_FD == OLD_FD, all we have to do is restore the
466 if (save_fd == old_fd)
470 return fcntl (old_fd, F_SETFD, flags);
478 if (dup3 (save_fd, old_fd, O_CLOEXEC) < 0)
484 if (dup2 (save_fd, old_fd) < 0)
486 if (flags != 0 && fcntl (old_fd, F_SETFD, flags) < 0)