From afadda2f36a83e2e839c24eafeb659d6def6e6ed Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 18 Oct 2023 10:42:10 +0800 Subject: [PATCH] coproc rclose function, coproc wclose function,coproc checkfd function --- bash-5.1/r_execute_cmd/src/lib.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bash-5.1/r_execute_cmd/src/lib.rs b/bash-5.1/r_execute_cmd/src/lib.rs index fe01068..f083789 100644 --- a/bash-5.1/r_execute_cmd/src/lib.rs +++ b/bash-5.1/r_execute_cmd/src/lib.rs @@ -1930,9 +1930,43 @@ pub unsafe extern "C" fn coproc_reap() { } } +#[no_mangle] +pub unsafe extern "C" fn coproc_rclose(mut cp: *mut coproc, mut fd: libc::c_int) { + if (*cp).c_rfd >= 0 && (*cp).c_rfd == fd { + close((*cp).c_rfd); + (*cp).c_rfd = -1; + } +} +#[no_mangle] +pub unsafe extern "C" fn coproc_wclose(mut cp: *mut coproc, mut fd: libc::c_int) { + if (*cp).c_wfd >= 0 && (*cp).c_wfd == fd { + close((*cp).c_wfd); + (*cp).c_wfd = -1; + } +} +#[no_mangle] +pub unsafe extern "C" fn coproc_checkfd(mut cp: *mut coproc, mut fd: libc::c_int) { + let mut update: libc::c_int = 0; + + update = 0 ; + if (*cp).c_rfd >= 0 && (*cp).c_rfd == fd { + let ref mut fresh28 = (*cp).c_rfd; + (*cp).c_rfd = -1; + update = -1; + } + if (*cp).c_wfd >= 0 && (*cp).c_wfd == fd { + let ref mut fresh29 = (*cp).c_wfd; + (*cp).c_wfd = -1; + update = -1; + } + if update != 0 { + coproc_setvars(cp); + } +} + -- Gitee