Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
use ffi; |
| 2 |
|
| 3 |
use libc; |
| 4 |
|
| 5 |
use std::slice; |
| 6 |
use std::str; |
| 7 |
use std::ptr; |
| 8 |
use std::ffi::CStr; |
| 9 |
|
| 10 |
pub fn decode_c_str(c_str: *const ffi::yaml_char_t) -> Option<String> { |
| 11 |
if c_str == ptr::null() { |
| 12 |
None |
| 13 |
} else { |
| 14 |
unsafe { |
| 15 |
let i8_str = c_str as *const i8; |
| 16 |
str::from_utf8(CStr::from_ptr(i8_str).to_bytes()).map(|s| s.to_string()).ok() |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
pub fn decode_buf(buf: *const ffi::yaml_char_t, length: libc::size_t) -> Option<String> { |
| 22 |
if buf == ptr::null() { |
| 23 |
None |
| 24 |
} else { |
| 25 |
unsafe { |
| 26 |
str::from_utf8(slice::from_raw_parts(buf, length as usize)).map(|s| { s.to_string() }).ok() |
| 27 |
} |
| 28 |
} |
| 29 |
} |