Convert *u8 native string users to *c_char

This commit is contained in:
Brian Anderson
2012-03-14 15:10:34 -07:00
parent e5dea87f43
commit 2a293ed8b8
11 changed files with 231 additions and 224 deletions

View File

@@ -38,8 +38,8 @@ export as_c_charp, fill_charp_buf;
native mod rustrt {
fn rust_env_pairs() -> [str];
fn rust_getcwd() -> str;
fn rust_path_is_dir(path: *u8) -> c_int;
fn rust_path_exists(path: *u8) -> c_int;
fn rust_path_is_dir(path: *libc::c_char) -> c_int;
fn rust_path_exists(path: *libc::c_char) -> c_int;
fn rust_list_files(path: str) -> [str];
fn rust_process_wait(handle: c_int) -> c_int;
}
@@ -58,7 +58,7 @@ fn env() -> [(str,str)] {
const tmpbuf_sz : uint = 1000u;
fn as_c_charp<T>(s: str, f: fn(*c_char) -> T) -> T {
str::as_buf(s) {|b| f(b as *c_char) }
str::as_c_str(s) {|b| f(b as *c_char) }
}
fn fill_charp_buf(f: fn(*mutable c_char, size_t) -> bool)
@@ -386,14 +386,14 @@ fn homedir() -> option<path> {
#[doc = "Indicates whether a path represents a directory"]
fn path_is_dir(p: path) -> bool {
str::as_buf(p) {|buf|
str::as_c_str(p) {|buf|
rustrt::rust_path_is_dir(buf) != 0 as c_int
}
}
#[doc = "Indicates whether a path exists"]
fn path_exists(p: path) -> bool {
str::as_buf(p) {|buf|
str::as_c_str(p) {|buf|
rustrt::rust_path_exists(buf) != 0 as c_int
}
}

View File

@@ -11,7 +11,8 @@ export waitpid;
#[abi = "cdecl"]
native mod rustrt {
fn rust_run_program(argv: **u8, envp: *c_void, dir: *u8,
fn rust_run_program(argv: **libc::c_char, envp: *c_void,
dir: *libc::c_char,
in_fd: c_int, out_fd: c_int, err_fd: c_int)
-> pid_t;
}
@@ -77,13 +78,13 @@ fn spawn_process(prog: str, args: [str],
}
fn with_argv<T>(prog: str, args: [str],
cb: fn(**u8) -> T) -> T unsafe {
let mut argptrs = str::as_buf(prog) {|b| [b] };
cb: fn(**libc::c_char) -> T) -> T unsafe {
let mut argptrs = str::as_c_str(prog) {|b| [b] };
let mut tmps = [];
for arg in args {
let t = @arg;
tmps += [t];
argptrs += str::as_buf(*t) {|b| [b] };
argptrs += str::as_c_str(*t) {|b| [b] };
}
argptrs += [ptr::null()];
vec::as_buf(argptrs, cb)
@@ -104,7 +105,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
for (k,v) in es {
let t = @(#fmt("%s=%s", k, v));
vec::push(tmps, t);
ptrs += str::as_buf(*t) {|b| [b]};
ptrs += str::as_c_str(*t) {|b| [b]};
}
ptrs += [ptr::null()];
vec::as_buf(ptrs) { |p| cb(::unsafe::reinterpret_cast(p)) }
@@ -140,9 +141,9 @@ fn with_envp<T>(env: option<[(str,str)]>,
}
fn with_dirp<T>(d: option<str>,
cb: fn(*u8) -> T) -> T unsafe {
cb: fn(*libc::c_char) -> T) -> T unsafe {
alt d {
some(dir) { str::as_buf(dir, cb) }
some(dir) { str::as_c_str(dir, cb) }
none { cb(ptr::null()) }
}
}