OxL Reference

data CStr

Namespace of helpers for reading C strings.

Example:

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

import c "string.h" { strdup }
import c "stdlib.h" { free }

fn main() io {
  let c = "copy me".toCString()
  unsafe {
    let d = strdup(c.asPtr())
    print(CStr.fromPtr(d))
    free(d.cast<u8>())
  }
}
Output
copy me
pub(api) data CStr

Since. 1.0.0-beta

Methods

fromPtr(p: *u8) -> str
Copies the NUL-terminated bytes at p into a str ("" for a null pointer).

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

See also