diff options
Diffstat (limited to 'src/libstd/c_str.rs')
| -rw-r--r-- | src/libstd/c_str.rs | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index cc6cd7666d6..fe332a60efa 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -310,7 +310,7 @@ impl<'a> ToCStr for &'a [u8] { let buf = malloc_raw(self_len + 1); ptr::copy_memory(buf, self.as_ptr(), self_len); - *ptr::mut_offset(buf, self_len as int) = 0; + *buf.offset(self_len as int) = 0; CString::new(buf as *libc::c_char, true) } @@ -368,7 +368,7 @@ impl<'a> Iterator<libc::c_char> for CChars<'a> { if ch == 0 { None } else { - self.ptr = unsafe { ptr::offset(self.ptr, 1) }; + self.ptr = unsafe { self.ptr.offset(1) }; Some(ch) } } @@ -429,18 +429,18 @@ mod tests { fn test_str_to_c_str() { "".to_c_str().with_ref(|buf| { unsafe { - assert_eq!(*ptr::offset(buf, 0), 0); + assert_eq!(*buf.offset(0), 0); } }); "hello".to_c_str().with_ref(|buf| { unsafe { - assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char); - assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char); - assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char); - assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char); - assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char); - assert_eq!(*ptr::offset(buf, 5), 0); + assert_eq!(*buf.offset(0), 'h' as libc::c_char); + assert_eq!(*buf.offset(1), 'e' as libc::c_char); + assert_eq!(*buf.offset(2), 'l' as libc::c_char); + assert_eq!(*buf.offset(3), 'l' as libc::c_char); + assert_eq!(*buf.offset(4), 'o' as libc::c_char); + assert_eq!(*buf.offset(5), 0); } }) } @@ -450,28 +450,28 @@ mod tests { let b: &[u8] = []; b.to_c_str().with_ref(|buf| { unsafe { - assert_eq!(*ptr::offset(buf, 0), 0); + assert_eq!(*buf.offset(0), 0); } }); let _ = bytes!("hello").to_c_str().with_ref(|buf| { unsafe { - assert_eq!(*ptr::offset(buf, 0), 'h' as libc::c_char); - assert_eq!(*ptr::offset(buf, 1), 'e' as libc::c_char); - assert_eq!(*ptr::offset(buf, 2), 'l' as libc::c_char); - assert_eq!(*ptr::offset(buf, 3), 'l' as libc::c_char); - assert_eq!(*ptr::offset(buf, 4), 'o' as libc::c_char); - assert_eq!(*ptr::offset(buf, 5), 0); + assert_eq!(*buf.offset(0), 'h' as libc::c_char); + assert_eq!(*buf.offset(1), 'e' as libc::c_char); + assert_eq!(*buf.offset(2), 'l' as libc::c_char); + assert_eq!(*buf.offset(3), 'l' as libc::c_char); + assert_eq!(*buf.offset(4), 'o' as libc::c_char); + assert_eq!(*buf.offset(5), 0); } }); let _ = bytes!("foo", 0xff).to_c_str().with_ref(|buf| { unsafe { - assert_eq!(*ptr::offset(buf, 0), 'f' as libc::c_char); - assert_eq!(*ptr::offset(buf, 1), 'o' as libc::c_char); - assert_eq!(*ptr::offset(buf, 2), 'o' as libc::c_char); - assert_eq!(*ptr::offset(buf, 3), 0xff as i8); - assert_eq!(*ptr::offset(buf, 4), 0); + assert_eq!(*buf.offset(0), 'f' as libc::c_char); + assert_eq!(*buf.offset(1), 'o' as libc::c_char); + assert_eq!(*buf.offset(2), 'o' as libc::c_char); + assert_eq!(*buf.offset(3), 0xff as i8); + assert_eq!(*buf.offset(4), 0); } }); } @@ -634,7 +634,6 @@ mod bench { use extra::test::BenchHarness; use libc; use prelude::*; - use ptr; #[inline] fn check(s: &str, c_str: *libc::c_char) { @@ -642,8 +641,8 @@ mod bench { for i in range(0, s.len()) { unsafe { assert_eq!( - *ptr::offset(s_buf, i as int) as libc::c_char, - *ptr::offset(c_str, i as int)); + *s_buf.offset(i as int) as libc::c_char, + *c_str.offset(i as int)); } } } |
