Skip to content

Commit 2170b51

Browse files
committed
impl NixPath for CString (maintains compatibility with exec*)
1 parent f778523 commit 2170b51

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub mod unistd;
7373

7474
use libc::c_char;
7575
use std::{ptr, result};
76-
use std::ffi::{CStr, OsStr};
76+
use std::ffi::{CStr, CString, OsStr};
7777
use std::path::{Path, PathBuf};
7878
use std::os::unix::ffi::OsStrExt;
7979
use std::fmt;
@@ -196,6 +196,17 @@ impl NixPath for CStr {
196196
}
197197
}
198198

199+
impl NixPath for CString {
200+
fn len(&self) -> usize {
201+
self.to_bytes().len()
202+
}
203+
204+
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
205+
where F: FnOnce(&CStr) -> T {
206+
self.as_c_str().with_nix_path(f)
207+
}
208+
}
209+
199210
impl NixPath for [u8] {
200211
fn len(&self) -> usize {
201212
self.len()

0 commit comments

Comments
 (0)