From 9e1fd8bcb8799216ae29450ae65b1a9d6a094544 Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Mon, 3 Jun 2024 10:06:47 +0800 Subject: [PATCH] add fd_ispipe --- utshell-0.5/r_general/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index 5873bfc5..ba8c7b63 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 -- Gitee