src/extname.rs in faster_path-0.1.13 vs src/extname.rs in faster_path-0.2.0

- old
+ new

@@ -1,20 +1,13 @@ -use libc::c_char; -use std::ffi::{CStr, CString}; use path_parsing::extract_last_path_segment; -#[no_mangle] -pub extern "C" fn extname(c_pth: *const c_char) -> *const c_char { - if c_pth.is_null() { - return c_pth - } +pub fn extname(pth: &str) -> String { + let name = extract_last_path_segment(pth); - let name = extract_last_path_segment(unsafe { CStr::from_ptr(c_pth) }.to_str().unwrap()); - if let Some(dot_i) = name.rfind('.') { if dot_i > 0 && dot_i < name.len() - 1 && name[..dot_i].chars().rev().next().unwrap() != '.' { - return CString::new(&name[dot_i..]).unwrap().into_raw() + return String::from(&name[dot_i..]) } } - CString::new("").unwrap().into_raw() + String::from("") }