use rlibc crate instead
This commit is contained in:
parent
5abf6b5d7c
commit
8965b061c2
@ -3,5 +3,11 @@ authors = ["Jorge Aparicio <japaricious@gmail.com>"]
|
|||||||
name = "rustc_builtins"
|
name = "rustc_builtins"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rlibc = { git = "https://github.com/alexcrichton/rlibc", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.3.1"
|
quickcheck = "0.3.1"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["rlibc/weak"]
|
||||||
|
@ -18,12 +18,13 @@ extern crate quickcheck;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
|
#[cfg(all(not(windows), not(target_os = "macos")))]
|
||||||
|
extern crate rlibc;
|
||||||
|
|
||||||
#[cfg(target_arch = "arm")]
|
#[cfg(target_arch = "arm")]
|
||||||
pub mod arm;
|
pub mod arm;
|
||||||
|
|
||||||
pub mod udiv;
|
pub mod udiv;
|
||||||
#[cfg(all(not(windows), not(target_os = "macos")))]
|
|
||||||
pub mod mem;
|
|
||||||
pub mod mul;
|
pub mod mul;
|
||||||
pub mod shift;
|
pub mod shift;
|
||||||
|
|
||||||
|
60
src/mem.rs
60
src/mem.rs
@ -1,60 +0,0 @@
|
|||||||
// NOTE Copied verbatim from the rlibc crate
|
|
||||||
// cf. https://crates.io/crates/rlibc
|
|
||||||
|
|
||||||
#[linkage = "weak"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
|
|
||||||
let mut i = 0;
|
|
||||||
while i < n {
|
|
||||||
*dest.offset(i as isize) = *src.offset(i as isize);
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
dest
|
|
||||||
}
|
|
||||||
|
|
||||||
#[linkage = "weak"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
|
|
||||||
if src < dest as *const u8 {
|
|
||||||
// copy from end
|
|
||||||
let mut i = n;
|
|
||||||
while i != 0 {
|
|
||||||
i -= 1;
|
|
||||||
*dest.offset(i as isize) = *src.offset(i as isize);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// copy from beginning
|
|
||||||
let mut i = 0;
|
|
||||||
while i < n {
|
|
||||||
*dest.offset(i as isize) = *src.offset(i as isize);
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dest
|
|
||||||
}
|
|
||||||
|
|
||||||
#[linkage = "weak"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: usize) -> *mut u8 {
|
|
||||||
let mut i = 0;
|
|
||||||
while i < n {
|
|
||||||
*s.offset(i as isize) = c as u8;
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
#[linkage = "weak"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
|
|
||||||
let mut i = 0;
|
|
||||||
while i < n {
|
|
||||||
let a = *s1.offset(i as isize);
|
|
||||||
let b = *s2.offset(i as isize);
|
|
||||||
if a != b {
|
|
||||||
return a as i32 - b as i32;
|
|
||||||
}
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
0
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user