diff --git a/src/compiler/rust/memstream.rs b/src/compiler/rust/memstream.rs index 2396455a52b..3d7bdcda01c 100644 --- a/src/compiler/rust/memstream.rs +++ b/src/compiler/rust/memstream.rs @@ -148,3 +148,24 @@ impl Drop for MemStream { } } } + +#[test] +fn test_memstream() { + use std::ffi::CString; + + let mut s = MemStream::new().unwrap(); + let test_str = "Test string"; + let test_c_str = CString::new(test_str).unwrap(); + let test_bytes = test_c_str.as_bytes(); + + unsafe { + bindings::compiler_rs_fwrite( + test_bytes.as_ptr().cast(), + 1, + test_bytes.len(), + s.c_file(), + ); + } + let res = s.take_utf8_string_lossy().unwrap(); + assert_eq!(res, test_str); +} diff --git a/src/compiler/rust/rust_helpers.c b/src/compiler/rust/rust_helpers.c index abe5edc2526..0cbc5e572d6 100644 --- a/src/compiler/rust/rust_helpers.c +++ b/src/compiler/rust/rust_helpers.c @@ -26,3 +26,10 @@ int compiler_rs_fseek(FILE *f, long offset, int whence) { return fseek(f, offset, whence); } + +size_t compiler_rs_fwrite(const void *ptr, + size_t size, size_t nmemb, + FILE *stream) +{ + return fwrite(ptr, size, nmemb, stream); +} diff --git a/src/compiler/rust/rust_helpers.h b/src/compiler/rust/rust_helpers.h index 20059e0f90b..3239359c14c 100644 --- a/src/compiler/rust/rust_helpers.h +++ b/src/compiler/rust/rust_helpers.h @@ -8,3 +8,6 @@ void compiler_rs_free(void *ptr); long compiler_rs_ftell(FILE *f); int compiler_rs_fseek(FILE *f, long offset, int whence); +size_t compiler_rs_fwrite(const void *ptr, + size_t size, size_t nmemb, + FILE *stream);