Sha256: ac557efa85a6679841f0fa156b43aa91ee3565575584cd83df17d269a3bc0889

Contents?: true

Size: 682 Bytes

Versions: 3

Compression:

Stored size: 682 Bytes

Contents

use std::path::{Path,MAIN_SEPARATOR};
use libc::c_char;
use std::ffi::{CStr,CString};
use std::str;

#[no_mangle]
pub extern fn dirname(string: *const c_char) -> *const c_char {
  let c_str = unsafe {
    assert!(!string.is_null());

    CStr::from_ptr(string)
  };

  let r_str = str::from_utf8(c_str.to_bytes()).unwrap();

  if r_str.is_empty() {
    return string
  }

  let path = Path::new(r_str).parent().unwrap_or(Path::new(""));

  let out_str = if !path.to_str().unwrap().is_empty() {
    format!("{}{}", path.to_str().unwrap(), MAIN_SEPARATOR)
  } else {
    format!("{}", path.to_str().unwrap())
  };

  let output = CString::new(out_str).unwrap();
  output.into_raw()
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faster_path-0.1.8 src/dirname.rs
faster_path-0.1.7 src/dirname.rs
faster_path-0.1.6 src/dirname.rs