about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-02-07 18:55:02 -0800
committerGraydon Hoare <graydon@mozilla.com>2012-02-07 19:57:03 -0800
commit93450abb4bf6a755b343ca459bbeff92540a7822 (patch)
treeee49c759c04ab7efb83025b9ed6b04878711ea39 /src/rt/rust_builtin.cpp
parent5131216fa6826509bb31672e5fde15b18eeff5d7 (diff)
downloadrust-93450abb4bf6a755b343ca459bbeff92540a7822.tar.gz
rust-93450abb4bf6a755b343ca459bbeff92540a7822.zip
Make process-spawning take environments and working directories, remove procsrv task from compiletest.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 8fbe0ed7888..76f80192e89 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -7,6 +7,10 @@
 #include "rust_scheduler.h"
 #include "sync/timer.h"
 
+#ifdef __APPLE__
+#include <crt_externs.h>
+#endif
+
 #if !defined(__WIN32__)
 #include <sys/time.h>
 #endif
@@ -73,6 +77,49 @@ rust_getcwd() {
     return make_str(task->kernel, cbuf, strlen(cbuf), "rust_str(getcwd");
 }
 
+
+#if defined(__WIN32__)
+extern "C" CDECL rust_vec *
+rust_env_pairs() {
+    rust_task *task = rust_task_thread::get_task();
+    size_t envc = 0;
+    LPTCH ch = GetEnvironmentStringsA();
+    LPTCH c;
+    for (c = ch; *c; c += strlen(c) + 1) {
+        ++envc;
+    }
+    c = ch;
+    rust_vec *v = (rust_vec *)
+        task->kernel->malloc(vec_size<rust_vec*>(envc),
+                       "str vec interior");
+    v->fill = v->alloc = sizeof(rust_vec*) * envc;
+    for (size_t i = 0; i < envc; ++i) {
+        size_t n = strlen(c);
+        rust_str *str = make_str(task->kernel, c, n, "str");
+        ((rust_str**)&v->data)[i] = str;
+        c += n + 1;
+    }
+    if (ch) {
+        FreeEnvironmentStrings(ch);
+    }
+    return v;
+}
+#else
+extern "C" CDECL rust_vec *
+rust_env_pairs() {
+    rust_task *task = rust_task_thread::get_task();
+#ifdef __APPLE__
+    char **environ = *_NSGetEnviron();
+#endif
+    char **e = environ;
+    size_t envc = 0;
+    while (*e) {
+        ++envc; ++e;
+    }
+    return make_str_vec(task->kernel, envc, environ);
+}
+#endif
+
 // TODO: Allow calling native functions that return double results.
 extern "C" CDECL
 void squareroot(double *input, double *output) {