v2 / vlib / builtin / wasm / wasi / string_notd_no_imports.v
16 lines · 15 sloc · 369 bytes · d559a62cfe3f3de0a5ca1e59f14e622960e3917b
Raw
1module builtin
2
3// tos creates a V string, given a C style pointer to a 0 terminated block.
4// Note: the memory block pointed by s is *reused, not copied*!
5// It will panic, when the pointer `s` is 0.
6// See also `tos_clone`.
7@[unsafe]
8pub fn tos(s &u8, len int) string {
9 if s == 0 {
10 panic('tos(): nil string')
11 }
12 return string{
13 str: unsafe { s }
14 len: len
15 }
16}
17