Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: str conversion fns should take *const u8 #8073

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,18 +777,18 @@ pub mod raw {
use vec::MutableVector;

/// Create a Rust string from a null-terminated *u8 buffer
pub unsafe fn from_buf(buf: *u8) -> ~str {
pub unsafe fn from_buf(buf: *const u8) -> ~str {
let mut curr = buf;
let mut i = 0u;
while *curr != 0u8 {
i += 1u;
curr = ptr::offset(buf, i);
curr = ptr::const_offset(buf, i);
}
return from_buf_len(buf, i);
}

/// Create a Rust string from a *u8 buffer of the given length
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
pub unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
let mut v: ~[u8] = vec::with_capacity(len + 1);
v.as_mut_buf(|vbuf, _len| {
ptr::copy_memory(vbuf, buf as *u8, len)
Expand All @@ -801,12 +801,12 @@ pub mod raw {
}

/// Create a Rust string from a null-terminated C string
pub unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
pub unsafe fn from_c_str(c_str: *const libc::c_char) -> ~str {
from_buf(::cast::transmute(c_str))
}

/// Create a Rust string from a `*c_char` buffer of the given length
pub unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str {
pub unsafe fn from_c_str_len(c_str: *const libc::c_char, len: uint) -> ~str {
from_buf_len(::cast::transmute(c_str), len)
}

Expand Down