From c310e041fd46605c6168289be560e288ad113251 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Fri, 7 Jan 2022 22:46:37 -0500 Subject: [PATCH] Export semihosting::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(); --- cortex-m-semihosting/src/hio.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cortex-m-semihosting/src/hio.rs b/cortex-m-semihosting/src/hio.rs index b6b6c7b7..684a5303 100644 --- a/cortex-m-semihosting/src/hio.rs +++ b/cortex-m-semihosting/src/hio.rs @@ -36,7 +36,10 @@ pub fn hstdout() -> Result { open(":tt\0", nr::open::W_TRUNC) } -fn open(name: &str, mode: usize) -> Result { +/// Open a file on the host. The filename must be zero-terminated. +pub fn open(name: &str, mode: usize) -> Result { + debug_assert_eq!(name.bytes().last(), Some(0), "the filename must be zero-terminated"); + let name = name.as_bytes(); match unsafe { syscall!(OPEN, name.as_ptr(), mode, name.len() - 1) } as isize { -1 => Err(()),