Skip to main content

fixfds

Function fixfds 

Source
pub fn fixfds(save: &[i32; 10])
Expand description

Port of static void fixfds(int *save) from Src/exec.c:4523.

C body:

int old_errno = errno;
int i;
for (i = 0; i != 10; i++)
    if (save[i] != -2)
        redup(save[i], i);
errno = old_errno;

Restore fds 0..9 from the save[10] slot array. -2 sentinel means “no save was made for this fd”; any other value is the stashed fd that gets dup2’d back via redup. Preserves the caller’s errno across the loop so a downstream caller diagnoses the original failure, not a noisy dup2 errno.