From eec80b496b8de2ee332b4ae04fbe00c7c93525b3 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Fri, 7 Jul 2017 11:39:39 -0600 Subject: Use libc from crates.io The libc crate has newlib bindings now, so we don't have to maintain them in-tree anymore --- ctr-std/src/sys/unix/memchr.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'ctr-std/src/sys') diff --git a/ctr-std/src/sys/unix/memchr.rs b/ctr-std/src/sys/unix/memchr.rs index d7e9c2b..ae8e3d0 100644 --- a/ctr-std/src/sys/unix/memchr.rs +++ b/ctr-std/src/sys/unix/memchr.rs @@ -28,24 +28,11 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option { } pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { - - #[cfg(target_os = "linux")] + // turns out that newlib doesn't have memrchr(), so we + // use the fallback version instead fn memrchr_specific(needle: u8, haystack: &[u8]) -> Option { - use libc; - - // GNU's memrchr() will - unlike memchr() - error if haystack is empty. - if haystack.is_empty() {return None} - let p = unsafe { - libc::memrchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len()) - }; - if p.is_null() { - None - } else { - Some(p as usize - (haystack.as_ptr() as usize)) - } + ::sys_common::memchr::fallback::memrchr(needle, haystack) } + memrchr_specific(needle, haystack) } -- cgit v1.2.3