Skip to main content

closem

Function closem 

Source
pub fn closem(how: i32, all: i32)
Expand description

Port of mod_export void closem(int how, int all) from Src/exec.c:4546.

C body:

int i;
for (i = 10; i <= max_zsh_fd; i++)
    if (fdtable[i] != FDT_UNUSED &&
        (all || (fdtable[i] != FDT_PROC_SUBST &&
                 fdtable[i] != FDT_EXTERNAL)) &&
        (how == FDT_UNUSED || (fdtable[i] & FDT_TYPE_MASK) == how)) {
        if (i == SHTTY) SHTTY = -1;
        zclose(i);
    }

Walk fds 10..=MAX_ZSH_FD and close every internal shell fd that matches the criteria. how == FDT_UNUSED matches all kinds (no type filter); otherwise only fds whose low-nibble type equals how are closed. all == 0 preserves user-visible fds (FDT_PROC_SUBST, FDT_EXTERNAL) since those need to outlive the shell’s internal-fd lifetime. SHTTY clearing prevents a stale reference if we just closed the controlling tty.