From 2c442007976111445ed0dfcd0ec45527cb462008 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 24 Apr 2020 10:41:39 +0200 Subject: [PATCH] use CStr for XAttr names Signed-off-by: Wolfgang Bumiller --- src/format.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/format.rs b/src/format.rs index ea25912..d1635ec 100644 --- a/src/format.rs +++ b/src/format.rs @@ -6,7 +6,7 @@ //! item data. use std::cmp::Ordering; -use std::ffi::OsStr; +use std::ffi::{CStr, OsStr}; use std::io; use std::mem::size_of; use std::os::unix::ffi::OsStrExt; @@ -310,8 +310,10 @@ impl XAttr { } } - pub fn name(&self) -> &[u8] { - &self.data[..self.name_len] + pub fn name(&self) -> &CStr { + unsafe { + CStr::from_bytes_with_nul_unchecked(&self.data[..self.name_len+1]) + } } pub fn value(&self) -> &[u8] { -- 2.39.5