diff --git a/src/lib.rs b/src/lib.rs index 826ed838c3..d20e819dc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,6 +119,22 @@ pub trait NixPath { where F: FnOnce(&CStr) -> T; } +impl NixPath for CStr { + fn len(&self) -> usize { + self.to_bytes().len() + } + + fn with_nix_path(&self, f: F) -> Result + where F: FnOnce(&CStr) -> T { + // Equivalence with the [u8] impl. + if self.len() >= PATH_MAX as usize { + return Err(Error::InvalidPath); + } + + Ok(f(self)) + } +} + impl NixPath for [u8] { fn len(&self) -> usize { self.len()