Move memory handling into string, do not use compiler_builtins for memory handling
This commit is contained in:
Generated
-2
@@ -379,7 +379,6 @@ name = "stdio"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbindgen 0.5.2",
|
||||
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
|
||||
"errno 0.1.0",
|
||||
"fcntl 0.1.0",
|
||||
"platform 0.1.0",
|
||||
@@ -405,7 +404,6 @@ name = "string"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbindgen 0.5.2",
|
||||
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
|
||||
"errno 0.1.0",
|
||||
"platform 0.1.0",
|
||||
"stdlib 0.1.0",
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ members = ["src/crt0"]
|
||||
cc = "1.0"
|
||||
|
||||
[dependencies]
|
||||
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
|
||||
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false }
|
||||
ctype = { path = "src/ctype" }
|
||||
errno = { path = "src/errno" }
|
||||
fcntl = { path = "src/fcntl" }
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef _BITS_STRING_H
|
||||
#define _BITS_STRING_H
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
void *memmove(void *dest, const void *src, size_t n);
|
||||
void *memset(void *s, int c, size_t n);
|
||||
|
||||
#endif /* _BITS_STRING_H */
|
||||
@@ -8,7 +8,6 @@ build = "build.rs"
|
||||
cbindgen = { path = "../../cbindgen" }
|
||||
|
||||
[dependencies]
|
||||
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
|
||||
platform = { path = "../platform" }
|
||||
va_list = { path = "../../va_list", features = ["no_std"] }
|
||||
fcntl = { path = "../fcntl" }
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
//! stdio implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/stdio.h.html
|
||||
|
||||
#![feature(compiler_builtins_lib)]
|
||||
#![no_std]
|
||||
|
||||
extern crate compiler_builtins;
|
||||
extern crate errno;
|
||||
extern crate fcntl;
|
||||
extern crate platform;
|
||||
|
||||
@@ -11,4 +11,3 @@ cbindgen = { path = "../../cbindgen" }
|
||||
platform = { path = "../platform" }
|
||||
stdlib = { path = "../stdlib" }
|
||||
errno = { path = "../errno" }
|
||||
compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false, features = ["mem"] }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
sys_includes = ["stddef.h", "stdint.h"]
|
||||
include_guard = "_STRING_H"
|
||||
trailer = "#include <bits/string.h>"
|
||||
language = "C"
|
||||
|
||||
[enum]
|
||||
|
||||
+67
-38
@@ -1,9 +1,7 @@
|
||||
//! string implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/string.h.html
|
||||
|
||||
#![feature(compiler_builtins_lib)]
|
||||
#![no_std]
|
||||
|
||||
extern crate compiler_builtins;
|
||||
extern crate errno;
|
||||
extern crate platform;
|
||||
extern crate stdlib;
|
||||
@@ -21,18 +19,15 @@ pub unsafe extern "C" fn memccpy(
|
||||
c: c_int,
|
||||
n: usize,
|
||||
) -> *mut c_void {
|
||||
use compiler_builtins::mem::memcpy;
|
||||
let dest = dest as *mut u8;
|
||||
let to = memchr(src, c, n);
|
||||
if to.is_null() {
|
||||
return to;
|
||||
}
|
||||
let src = src as *mut u8;
|
||||
let dist = (to as usize) - (src as usize);
|
||||
if memcpy(dest, src, dist).is_null() {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
dest.offset(dist as isize + 1) as *mut c_void
|
||||
(dest as *mut u8).offset(dist as isize + 1) as *mut c_void
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -47,41 +42,75 @@ pub unsafe extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_
|
||||
ptr::null_mut()
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn memcmp(
|
||||
// s1: *const c_void,
|
||||
// s2: *const c_void,
|
||||
// n: usize,
|
||||
// ) -> c_int {
|
||||
// unimplemented!();
|
||||
// }
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcmp(
|
||||
s1: *const c_void,
|
||||
s2: *const c_void,
|
||||
n: usize,
|
||||
) -> c_int {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
let a = *(s1 as *const u8).offset(i as isize);
|
||||
let b = *(s2 as *const u8).offset(i as isize);
|
||||
if a != b {
|
||||
return a as i32 - b as i32;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn memcpy(
|
||||
// s1: *mut c_void,
|
||||
// s2: *const c_void,
|
||||
// n: usize,
|
||||
// ) -> *mut c_void {
|
||||
// unimplemented!();
|
||||
// }
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcpy(
|
||||
s1: *mut c_void,
|
||||
s2: *const c_void,
|
||||
n: usize,
|
||||
) -> *mut c_void {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
|
||||
i += 1;
|
||||
}
|
||||
s1
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn memmove(
|
||||
// s1: *mut c_void,
|
||||
// s2: *const c_void,
|
||||
// n: usize,
|
||||
// ) -> *mut c_void {
|
||||
// unimplemented!();
|
||||
// }
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memmove(
|
||||
s1: *mut c_void,
|
||||
s2: *const c_void,
|
||||
n: usize,
|
||||
) -> *mut c_void {
|
||||
if s2 < s1 as *const c_void {
|
||||
// copy from end
|
||||
let mut i = n;
|
||||
while i != 0 {
|
||||
i -= 1;
|
||||
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
|
||||
}
|
||||
} else {
|
||||
// copy from beginning
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(s1 as *mut u8).offset(i as isize) = *(s2 as *const u8).offset(i as isize);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
s1
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
// pub extern "C" fn memset(
|
||||
// s: *mut c_void,
|
||||
// c: c_int,
|
||||
// n: usize,
|
||||
// ) -> *mut c_void {
|
||||
// unimplemented!();
|
||||
// }
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memset(
|
||||
s: *mut c_void,
|
||||
c: c_int,
|
||||
n: usize,
|
||||
) -> *mut c_void {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(s as *mut u8).offset(i as isize) = c as u8;
|
||||
i += 1;
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strcat(s1: *mut c_char, s2: *const c_char) -> *mut c_char {
|
||||
|
||||
Reference in New Issue
Block a user