Sha256: 959a90b7af5f6b5dfa329b740c38f2827f8633357f9f5a41576b58c6dcbff469

Contents?: true

Size: 567 Bytes

Versions: 4

Compression:

Stored size: 567 Bytes

Contents

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
  }

  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()
    }
  }

  CString::new("").unwrap().into_raw()
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
faster_path-0.1.13 src/extname.rs
faster_path-0.1.12 src/extname.rs
faster_path-0.1.11 src/extname.rs
faster_path-0.1.10 src/extname.rs