rustc: Add str_from_cstr() and str_from_buf() functions to the standard library, as well as a test case

This commit is contained in:
Patrick Walton
2011-03-16 18:40:51 -07:00
parent 320ac6b8eb
commit ea7197e2cf
4 changed files with 48 additions and 0 deletions

View File

@@ -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)
{