diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index 5873bfc5d5b35770b41c8b8fc51c3d6a1b1264fa..ba8c7b63a85cb3f8fcbba9cfd18c8b1b1e16195e 100644 --- a/utshell-0.5/r_general/src/lib.rs +++ b/utshell-0.5/r_general/src/lib.rs @@ -987,4 +987,23 @@ pub unsafe extern "C" fn sh_unset_nodelay_mode(mut fd: libc::c_int) -> libc::c_i } return 0; +} + +/* Just a wrapper for the define in include/filecntl.h */ +#[no_mangle] +pub unsafe extern "C" fn sh_setclexec(mut fd: libc::c_int) -> libc::c_int { + return SET_CLOSE_ON_EXEC!(fd); +} + +/* Return 1 if file descriptor FD is valid; 0 otherwise. */ +#[no_mangle] +pub unsafe extern "C" fn sh_validfd(mut fd: libc::c_int) -> libc::c_int { + return (fcntl(fd, F_GETFD, 0) >= 0) as libc::c_int; +} + +#[no_mangle] +pub unsafe extern "C" fn fd_ispipe(mut fd: libc::c_int) -> libc::c_int { + *__errno_location() = 0; + return (lseek(fd, 0 as libc::c_long, SEEK_CUR) < 0 as libc::c_int as libc::c_long + && *__errno_location() == ESPIPE) as libc::c_int; } \ No newline at end of file