From b24f1576edc24dd9a4e16c24f9dd500c77bbb2bf Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Fri, 31 May 2024 09:45:57 +0800 Subject: [PATCH] add sh_unset_nodelay_mode --- utshell-0.5/r_general/src/lib.rs | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index ac8d7035..5873bfc5 100644 --- a/utshell-0.5/r_general/src/lib.rs +++ b/utshell-0.5/r_general/src/lib.rs @@ -939,5 +939,52 @@ pub unsafe extern "C" fn assignment( indx += 1; indx; } + return 0; +} + +#[no_mangle] +pub unsafe extern "C" fn line_isblank(mut line: *const libc::c_char) -> libc::c_int { + let mut i: libc::c_int = 0; + + if line.is_null() { + return 0; /* XXX */ + } + + i = 0; + while *line.offset(i as isize) != 0 { + if isblank!(*line.offset(i as isize) as libc::c_uchar as libc::c_int as isize) + == 0 as libc::c_int + { + break; + } + i += 1; + i; + } + return (*line.offset(i as isize) as libc::c_int == '\0' as i32) as libc::c_int; +} + +/* Make sure no-delay mode is not set on file descriptor FD. */ +#[no_mangle] +pub unsafe extern "C" fn sh_unset_nodelay_mode(mut fd: libc::c_int) -> libc::c_int { + let mut flags: libc::c_int = 0; + let mut bflags: libc::c_int = 0; + + flags = fcntl(fd, F_GETFL, 0 as libc::c_int); + if flags < 0 as libc::c_int { + return -(1 as libc::c_int); + } + + bflags = 0 as libc::c_int; + + /* This is defined to O_NDELAY in filecntl.h if O_NONBLOCK is not present + and O_NDELAY is defined. */ + bflags |= O_NONBLOCK; + bflags |= O_NDELAY; + + if flags & bflags != 0 { + flags &= !bflags; + return fcntl(fd, F_SETFL, flags); + } + return 0; } \ No newline at end of file -- Gitee