Sha256: 8be638de5b6e81ddad5b03c9280f4bd29a4977f85bda1fe3bedfe0ebcd47ff75

Contents?: true

Size: 734 Bytes

Versions: 1

Compression:

Stored size: 734 Bytes

Contents

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

#[no_mangle]
pub extern "C" fn add_trailing_separator(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_or("");

    if r_str.is_empty() {
        return string;
    }

    let path = Path::new(r_str);
    let out_str = if !(path.to_str().unwrap().chars().last().unwrap() == '/') {
        format!("{}{}", path.to_str().unwrap(), MAIN_SEPARATOR)
    } else {
        path.to_str().unwrap().to_string()
    };

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faster_path-0.1.7 src/add_trailing_separator.rs