Skip to content

Commit 4bc26ce

Browse files
olsonjefferybrson
authored andcommitted
rt/core: impl os::getcwd() in rust ref rust-lang#4812
1 parent 878a310 commit 4bc26ce

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

src/libcore/os.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ pub mod rustrt {
6868
}
6969

7070
pub const TMPBUF_SZ : uint = 1000u;
71+
const BUF_BYTES : uint = 2048u;
7172

7273
pub fn getcwd() -> Path {
74+
let buf = [0 as libc::c_char, ..BUF_BYTES];
7375
unsafe {
74-
Path(rustrt::rust_getcwd())
76+
if(0 as *libc::c_char == libc::getcwd(
77+
&buf[0],
78+
BUF_BYTES as libc::size_t)) {
79+
fail!();
80+
}
81+
Path(str::raw::from_c_str(&buf[0]))
7582
}
7683
}
7784

src/rt/rust_builtin.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,6 @@ timegm(struct tm *tm)
5252
}
5353
#endif
5454

55-
extern "C" CDECL rust_str *
56-
rust_getcwd() {
57-
rust_task *task = rust_get_current_task();
58-
LOG(task, task, "rust_getcwd()");
59-
60-
char cbuf[BUF_BYTES];
61-
62-
#if defined(__WIN32__)
63-
if (!_getcwd(cbuf, sizeof(cbuf))) {
64-
#else
65-
if (!getcwd(cbuf, sizeof(cbuf))) {
66-
#endif
67-
task->fail();
68-
return NULL;
69-
}
70-
71-
return make_str(task->kernel, cbuf, strlen(cbuf), "rust_str(getcwd)");
72-
}
73-
7455
#if defined(__WIN32__)
7556
extern "C" CDECL rust_vec_box *
7657
rust_env_pairs() {

src/rt/rustrt.def.in

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ rust_new_task_in_sched
2929
rust_num_threads
3030
rust_path_is_dir
3131
rust_path_exists
32-
rust_getcwd
3332
rust_get_stdin
3433
rust_get_stdout
3534
rust_get_stderr
@@ -43,7 +42,6 @@ rust_sched_current_nonlazy_threads
4342
rust_sched_threads
4443
rust_set_exit_status
4544
rust_start
46-
rust_getcwd
4745
rust_env_pairs
4846
rust_task_yield
4947
rust_task_is_unwinding

0 commit comments

Comments
 (0)