From ea7197e2cf921211fb3b82ad45452c2095f5a589 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 16 Mar 2011 18:40:51 -0700 Subject: rustc: Add str_from_cstr() and str_from_buf() functions to the standard library, as well as a test case --- src/rt/rust_builtin.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/rt') diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index fcea449d..1f17fc8c 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) { -- cgit v1.2.3