OxL Reference

method CStr.fromPtr

Copies the NUL-terminated bytes at p into a str ("" for a null pointer). The bytes should be UTF-8.

Example:

oxl✓ checked in CI
use std.ffi { CStr, null }

fn main() io {
  let none_here = unsafe { CStr.fromPtr(null<u8>()) }
  let s = "native".toCString()
  print("[{none_here}] {unsafe { CStr.fromPtr(s.asPtr()) }}")
}
Output
[] native
pub(api) static unsafe fn fromPtr(p: *u8) -> str

Complexity. O(n) in the length of the C string.

Since. 1.0.0-beta

Parameters

NameType
p*u8

Returns

str

Effects

none declared (pure unless the body says otherwise)

Defined in: std/ffi/ffi.oxl:138

See also