diff --git a/CHANGELOG.md b/CHANGELOG.md index 9480412..f53511d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# Upcoming Release + +## Added + +- [[#72](https://github.com/rust-vmm/vm-fdt/pull/72)] Added + `FdtWriter::property_cstring` method to allow setting `&CStr` string + value directly. + +## Fixed + # v0.3.0 ## Added diff --git a/src/writer.rs b/src/writer.rs index f8ccbfc..dad7e12 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -10,6 +10,7 @@ use alloc::string::String; use alloc::vec::Vec; use core::cmp::{Ord, Ordering}; use core::convert::TryInto; +use core::ffi::CStr; use core::fmt; use core::mem::size_of_val; #[cfg(feature = "std")] @@ -448,7 +449,12 @@ impl FdtWriter { /// Write a string property. pub fn property_string(&mut self, name: &str, val: &str) -> Result<()> { let cstr_value = CString::new(val).map_err(|_| Error::InvalidString)?; - self.property(name, cstr_value.to_bytes_with_nul()) + self.property_cstring(name, &cstr_value) + } + + /// Write a C string property. + pub fn property_cstring(&mut self, name: &str, val: &CStr) -> Result<()> { + self.property(name, val.to_bytes_with_nul()) } /// Write a stringlist property.