Sha256: 6a96ca7049580743e195ee5a552594d125c82e1c3814216692f8a15d5bed8f4c
Contents?: true
Size: 1021 Bytes
Versions: 3
Compression:
Stored size: 1021 Bytes
Contents
use std::path::MAIN_SEPARATOR; use libc::c_char; use std::ffi::{CStr, CString}; use path_parsing::{last_sep_i, last_non_sep_i, last_non_sep_i_before}; #[no_mangle] pub extern "C" fn dirname(path: *const c_char) -> *const c_char { if path.is_null() { return path } let r_str = unsafe { CStr::from_ptr(path) }.to_str().unwrap(); if r_str.is_empty() { return CString::new(".").unwrap().into_raw(); } let non_sep_i = last_non_sep_i(r_str); if non_sep_i == -1 { return CString::new(MAIN_SEPARATOR.to_string()).unwrap().into_raw(); } let sep_i = last_sep_i(r_str, non_sep_i); if sep_i == -1 { return CString::new(".").unwrap().into_raw(); } if sep_i == 0 { return CString::new(MAIN_SEPARATOR.to_string()).unwrap().into_raw(); } let non_sep_i2 = last_non_sep_i_before(r_str, sep_i); if non_sep_i2 != -1 { return CString::new(&r_str[..(non_sep_i2 + 1) as usize]).unwrap().into_raw(); } else { return CString::new(MAIN_SEPARATOR.to_string()).unwrap().into_raw(); } }
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
faster_path-0.1.12 | src/dirname.rs |
faster_path-0.1.11 | src/dirname.rs |
faster_path-0.1.10 | src/dirname.rs |