From 4bc26ce575b4bc6f7254a2cfe9fee0a08de90b49 Mon Sep 17 00:00:00 2001 From: Jeff Olson Date: Wed, 13 Feb 2013 23:00:34 -0800 Subject: [PATCH] rt/core: impl os::getcwd() in rust ref #4812 --- src/libcore/os.rs | 9 ++++++++- src/rt/rust_builtin.cpp | 19 ------------------- src/rt/rustrt.def.in | 2 -- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/libcore/os.rs b/src/libcore/os.rs index ba16c14a85add..43e20a1a83f37 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -68,10 +68,17 @@ pub mod rustrt { } pub const TMPBUF_SZ : uint = 1000u; +const BUF_BYTES : uint = 2048u; pub fn getcwd() -> Path { + let buf = [0 as libc::c_char, ..BUF_BYTES]; unsafe { - Path(rustrt::rust_getcwd()) + if(0 as *libc::c_char == libc::getcwd( + &buf[0], + BUF_BYTES as libc::size_t)) { + fail!(); + } + Path(str::raw::from_c_str(&buf[0])) } } diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 1243d82460346..750962b37e8f3 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -52,25 +52,6 @@ timegm(struct tm *tm) } #endif -extern "C" CDECL rust_str * -rust_getcwd() { - rust_task *task = rust_get_current_task(); - LOG(task, task, "rust_getcwd()"); - - char cbuf[BUF_BYTES]; - -#if defined(__WIN32__) - if (!_getcwd(cbuf, sizeof(cbuf))) { -#else - if (!getcwd(cbuf, sizeof(cbuf))) { -#endif - task->fail(); - return NULL; - } - - return make_str(task->kernel, cbuf, strlen(cbuf), "rust_str(getcwd)"); -} - #if defined(__WIN32__) extern "C" CDECL rust_vec_box * rust_env_pairs() { diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index fca10ac3ef49b..ddbd4729782eb 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -29,7 +29,6 @@ rust_new_task_in_sched rust_num_threads rust_path_is_dir rust_path_exists -rust_getcwd rust_get_stdin rust_get_stdout rust_get_stderr @@ -43,7 +42,6 @@ rust_sched_current_nonlazy_threads rust_sched_threads rust_set_exit_status rust_start -rust_getcwd rust_env_pairs rust_task_yield rust_task_is_unwinding