copyStringFromOwnedFfiPtr function

String? copyStringFromOwnedFfiPtr(
  1. Pointer<Char> text
)

From an owned, UTF-8 encoded C-string (null-byte terminated) allocated in native code, copy the string into the Dart VM Heap as a Stringa and then immediately free the owned pointer.

Implementation

String? copyStringFromOwnedFfiPtr(Pointer<Char> text) {
  if (text == nullptr) {
    return null;
  }

  final String out = text.cast<Utf8>().toDartString();
  malloc.free(text);
  return out;
}