From e15879ff7b931f6413777b4b5948ceccaed251e9 Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Tue, 4 Jun 2024 09:41:09 +0800 Subject: [PATCH] add check_binary_file --- utshell-0.5/r_general/src/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index fdc55516..3af1febe 100644 --- a/utshell-0.5/r_general/src/lib.rs +++ b/utshell-0.5/r_general/src/lib.rs @@ -1163,4 +1163,31 @@ pub unsafe extern "C" fn move_to_high_fd( /* OK, we didn't find one less than our artificial maximum; return the original file descriptor. */ return fd; -} \ No newline at end of file +} + +/* Return non-zero if the characters from SAMPLE are not all valid +characters to be found in the first line of a shell script. We +check up to the first newline, or SAMPLE_LEN, whichever comes first. +All of the characters must be printable or whitespace. */ +#[no_mangle] +pub unsafe extern "C" fn check_binary_file( + mut sample: *const libc::c_char, + mut sample_len: libc::c_int, +) -> libc::c_int { + let mut i: libc::c_int = 0; + let mut c: libc::c_uchar = 0; + + while i < sample_len { + c = *sample.offset(i as isize) as libc::c_uchar; + if c as libc::c_int == '\n' as i32 { + return 0 as libc::c_int; + } + if c as libc::c_int == '\0' as i32 { + return 1 as libc::c_int; + } + i += 1; + i; + } + + return 0 as libc::c_int; +} -- Gitee