// Native-target atomic-write primitive. Calls into mnemo_atomic_write
// from native_stub.c, which does tmp + write + fsync + rename + cleanup
// on failure. Strings are passed as UTF-8 encoded Bytes.
///|
fn ffi_atomic_write_impl(path : String, content : String) -> Unit {
let path_bytes = @utf8.encode(path.view())
let content_bytes = @utf8.encode(content.view())
if mnemo_atomic_write(path_bytes, content_bytes) != 1 {
abort("memory_store: atomic write failed: " + path)
}
}
#borrow(path, content)
extern "C" fn mnemo_atomic_write(path : Bytes, content : Bytes) -> Int = "mnemo_atomic_write"
///| Native counterpart of the JS ffi_ms_try_write — same no-throw
///| contract, used only by the inline failure-path test.
fn ffi_ms_try_write(path : String, content : String) -> Bool {
let path_bytes = @utf8.encode(path.view())
let content_bytes = @utf8.encode(content.view())
mnemo_atomic_write(path_bytes, content_bytes) == 1
}