mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 07:26:29 +03:00
@@ -12,6 +12,10 @@ pub(crate) use libc::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) unsafe fn strcasecmp(s1: *const libc::c_char, s2: *const libc::c_char) -> libc::c_int {
|
pub(crate) unsafe fn strcasecmp(s1: *const libc::c_char, s2: *const libc::c_char) -> libc::c_int {
|
||||||
|
if s1.is_null() || s2.is_null() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
let s1 = std::ffi::CStr::from_ptr(s1)
|
let s1 = std::ffi::CStr::from_ptr(s1)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_lowercase();
|
.to_lowercase();
|
||||||
@@ -30,16 +34,23 @@ pub(crate) unsafe fn strncasecmp(
|
|||||||
s2: *const libc::c_char,
|
s2: *const libc::c_char,
|
||||||
n: libc::size_t,
|
n: libc::size_t,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let s1 = std::ffi::CStr::from_ptr(s1)
|
if s1.is_null() || s2.is_null() {
|
||||||
.to_string_lossy()
|
return 1;
|
||||||
.to_lowercase();
|
}
|
||||||
let s2 = std::ffi::CStr::from_ptr(s2)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_lowercase();
|
|
||||||
let m1 = std::cmp::min(n, s1.len());
|
|
||||||
let m2 = std::cmp::min(n, s2.len());
|
|
||||||
|
|
||||||
if s1[..m1] == s2[..m2] {
|
// s1 and s2 might not be null terminated.
|
||||||
|
|
||||||
|
let s1_slice = std::slice::from_raw_parts(s1 as *const u8, n);
|
||||||
|
let s2_slice = std::slice::from_raw_parts(s2 as *const u8, n);
|
||||||
|
|
||||||
|
let s1 = std::ffi::CStr::from_bytes_with_nul_unchecked(s1_slice)
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_lowercase();
|
||||||
|
let s2 = std::ffi::CStr::from_bytes_with_nul_unchecked(s2_slice)
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_lowercase();
|
||||||
|
|
||||||
|
if s1 == s2 {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
|
|||||||
Reference in New Issue
Block a user