Skip to content

Commit 5d336f1

Browse files
committed
Export semihistory::hio::open()
It's useful for opening various files on the host. For example: let mut file = open("file.bin\0", nr::open::RW_TRUNC_BINARY).unwrap(); file.write_all(b"Some binary content").unwrap();
1 parent ef049c9 commit 5d336f1

File tree

1 file changed

+4
-1
lines changed
  • cortex-m-semihosting/src

1 file changed

+4
-1
lines changed

cortex-m-semihosting/src/hio.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ pub fn hstdout() -> Result<HostStream, ()> {
3636
open(":tt\0", nr::open::W_TRUNC)
3737
}
3838

39-
fn open(name: &str, mode: usize) -> Result<HostStream, ()> {
39+
/// Open a file on the host. The filename must be zero-terminated.
40+
pub fn open(name: &str, mode: usize) -> Result<HostStream, ()> {
41+
debug_assert_eq!(name.bytes().last(), Some(0), "the filename must be zero-terminated");
42+
4043
let name = name.as_bytes();
4144
match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as isize {
4245
-1 => Err(()),

0 commit comments

Comments
 (0)