mirror of
https://github.com/chatmail/core.git
synced 2026-04-18 22:16:30 +03:00
Ci updates & closer to windows builds
* chore: update some ci * feat: no more libiconv * refactor: updates for updated mmime api * fixup: correct mmime path * cleanup * use newer visual studio * Update appveyor.yml * unify libc imports and improve windows situation * refactor: use rust based sleep * improve cross platform state of types * docs: update readme badges
This commit is contained in:
committed by
GitHub
parent
b992b8ea09
commit
342e416b4e
66
src/x.rs
66
src/x.rs
@@ -4,15 +4,23 @@ use crate::types::*;
|
||||
pub use libc::{
|
||||
atoi, calloc, close, closedir, exit, fclose, fgets, fopen, fread, free, fseek, ftell, fwrite,
|
||||
gmtime, gmtime_r, localtime, localtime_r, malloc, memcmp, memcpy, memmove, memset, mkdir, open,
|
||||
opendir, printf, read, readdir, realloc, remove, sleep, snprintf, sprintf, sscanf, strcasecmp,
|
||||
strcat, strchr, strcmp, strcpy, strcspn, strdup, strlen, strncasecmp, strncmp, strncpy,
|
||||
strrchr, strspn, strstr, strtol, system, time, tolower as __tolower, toupper as __toupper,
|
||||
usleep, write,
|
||||
opendir, printf, read, readdir, realloc, remove, sprintf, sscanf, strcat, strchr, strcmp,
|
||||
strcpy, strcspn, strlen, strncmp, strncpy, strrchr, strspn, strstr, strtol, system, time,
|
||||
tolower, write,
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
// pub static mut _DefaultRuneLocale: _RuneLocale;
|
||||
pub unsafe fn strdup(s: *const libc::c_char) -> *mut libc::c_char {
|
||||
let slen = libc::strlen(s);
|
||||
let result = libc::malloc(slen + 1);
|
||||
if result.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
|
||||
libc::memcpy(result, s as *const _, slen + 1);
|
||||
result as *mut _
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn clock() -> libc::clock_t;
|
||||
pub fn qsort(
|
||||
__base: *mut libc::c_void,
|
||||
@@ -53,12 +61,23 @@ extern "C" {
|
||||
_: *const libc::c_char,
|
||||
) -> !;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn snprintf(
|
||||
s: *mut libc::c_char,
|
||||
n: libc::size_t,
|
||||
format: *const libc::c_char,
|
||||
_: ...
|
||||
) -> libc::c_int;
|
||||
|
||||
// -- DC Methods
|
||||
|
||||
pub fn dc_strbuilder_catf(_: *mut dc_strbuilder_t, format: *const libc::c_char, _: ...);
|
||||
pub fn dc_mprintf(format: *const libc::c_char, _: ...) -> *mut libc::c_char;
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub(crate) use libc::snprintf;
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
pub unsafe extern "C" fn __assert_rtn(
|
||||
a: *const libc::c_char,
|
||||
@@ -77,6 +96,41 @@ pub unsafe fn atof(nptr: *mut libc::c_char) -> libc::c_double {
|
||||
libc::strtod(nptr, std::ptr::null_mut())
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn strcasecmp(s1: *const libc::c_char, s2: *const libc::c_char) -> libc::c_int {
|
||||
let s1 = std::ffi::CStr::from_ptr(s1)
|
||||
.to_string_lossy()
|
||||
.to_lowercase();
|
||||
let s2 = std::ffi::CStr::from_ptr(s2)
|
||||
.to_string_lossy()
|
||||
.to_lowercase();
|
||||
if s1 == s2 {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn strncasecmp(
|
||||
s1: *const libc::c_char,
|
||||
s2: *const libc::c_char,
|
||||
n: libc::size_t,
|
||||
) -> libc::c_int {
|
||||
let s1 = std::ffi::CStr::from_ptr(s1)
|
||||
.to_string_lossy()
|
||||
.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] {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user