about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-16 18:40:51 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-03-16 18:42:08 -0700
commitea7197e2cf921211fb3b82ad45452c2095f5a589 (patch)
tree7023e317dcc61a637388a42b746d91079413eed2 /src/rt/rust_builtin.cpp
parent320ac6b8eba10b51ba10443198d319b8ea0a657d (diff)
downloadrust-ea7197e2cf921211fb3b82ad45452c2095f5a589.tar.gz
rust-ea7197e2cf921211fb3b82ad45452c2095f5a589.zip
rustc: Add str_from_cstr() and str_from_buf() functions to the standard library, as well as a test case
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index fcea449ddd9..1f17fc8c075 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -207,6 +207,29 @@ str_from_vec(rust_task *task, rust_vec *v)
     return st;
 }
 
+extern "C" CDECL rust_str *
+str_from_cstr(rust_task *task, char *sbuf)
+{
+    size_t len = strlen(sbuf) + 1;
+    rust_str *st = vec_alloc_with_data(task, len, len, 1, sbuf);
+    if (!st) {
+        task->fail(2);
+        return NULL;
+    }
+    return st;
+}
+
+extern "C" CDECL rust_str *
+str_from_buf(rust_task *task, char *buf, unsigned int len) {
+    rust_str *st = vec_alloc_with_data(task, len + 1, len, 1, buf);
+    if (!st) {
+        task->fail(2);
+        return NULL;
+    }
+    st->data[st->fill++] = '\0';
+    return st;
+}
+
 extern "C" CDECL void *
 rand_new(rust_task *task)
 {