mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
more rust, less libc
This commit is contained in:
parent
ddc67c2a19
commit
b80b59125e
1 changed files with 3 additions and 16 deletions
|
@ -619,24 +619,11 @@ fn roc_run_executable_file_path(cwd: &Path, binary_bytes: &mut [u8]) -> std::io:
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: this `fd` is special, using the rust `std::fs::File` functions does not work
|
let path = PathBuf::from(format!("/proc/self/fd/{}", fd));
|
||||||
let written = unsafe { libc::write(fd, binary_bytes.as_ptr().cast(), binary_bytes.len()) };
|
|
||||||
|
|
||||||
if written == -1 {
|
std::fs::write(&path, binary_bytes)?;
|
||||||
internal_error!("libc::write() failed: {:?}", errno::errno());
|
|
||||||
}
|
|
||||||
|
|
||||||
if written != binary_bytes.len() as isize {
|
Ok(path)
|
||||||
internal_error!(
|
|
||||||
"libc::write() did not write the correct number of bytes: reported {}, should be {}",
|
|
||||||
written,
|
|
||||||
binary_bytes.len(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = format!("/proc/self/fd/{}", fd);
|
|
||||||
|
|
||||||
Ok(PathBuf::from(path))
|
|
||||||
} else {
|
} else {
|
||||||
// we have not found a way yet to use a virtual file on MacOs. Hence we fall back to just
|
// we have not found a way yet to use a virtual file on MacOs. Hence we fall back to just
|
||||||
// writing the file to the file system, and using that file.
|
// writing the file to the file system, and using that file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue