Skip to content

Commit

Permalink
Use c_char for C strings (instead of i8)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosthekiss committed Jan 19, 2015
1 parent 5bdbc68 commit 2efe319
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern crate log;
#[macro_use]
extern crate bitflags;

use libc::{c_double, c_float, c_int};
use libc::{c_char, c_double, c_float, c_int};
use libc::{c_ushort, c_void};
use std::ffi::CString;
use std::mem;
Expand Down Expand Up @@ -722,13 +722,13 @@ pub fn get_version() -> Version {
}

/// Replacement for `String::from_raw_buf`
pub unsafe fn string_from_c_str(c_str: *const i8) -> String {
pub unsafe fn string_from_c_str(c_str: *const c_char) -> String {
use std::ffi::c_str_to_bytes;
String::from_utf8_lossy(c_str_to_bytes(&c_str)).into_owned()
}

/// Replacement for `ToCStr::with_c_str`
pub fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const i8) -> T {
pub fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const c_char) -> T {
let c_str = CString::from_slice(s.as_bytes());
f(c_str.as_slice_with_nul().as_ptr())
}
Expand Down

0 comments on commit 2efe319

Please sign in to comment.