about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-06-17 11:12:51 -0700
committerEric Holk <eholk@mozilla.com>2011-06-17 15:53:19 -0700
commita40116b3980610c28f97740d4a40ef79bf89a59a (patch)
tree2cd8e82fde195b865ea38aabe5d2309fdb65729e /src/rt
parent175fd8ee73743a08174b5fa7203798008c927fea (diff)
downloadrust-a40116b3980610c28f97740d4a40ef79bf89a59a.tar.gz
rust-a40116b3980610c28f97740d4a40ef79bf89a59a.zip
stdlib: added getcwd and a convenience function to make relative paths absolute. This will be helpful for #441.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_builtin.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index c713a923d46..afa022fe533 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -55,6 +55,36 @@ last_os_error(rust_task *task) {
     return st;
 }
 
+extern "C" CDECL rust_str *
+rust_getcwd(rust_task *task) {
+    rust_dom *dom = task->dom;
+    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(1);
+        return NULL;
+    }
+
+    size_t fill = strlen(cbuf) + 1;
+    size_t alloc = next_power_of_two(sizeof(rust_str) + fill);
+    void *mem = dom->malloc(alloc, memory_region::LOCAL);
+    if (!mem) {
+        task->fail(1);
+        return NULL;
+    }
+
+    rust_str *st;
+    st = new (mem) rust_str(dom, alloc, fill, (const uint8_t *)cbuf);
+
+    return st;    
+}
+
 extern "C" CDECL
 void squareroot(rust_task *task, double *input, double *output) {
     *output = sqrt(*input);