extern crate libc;
+use std::ffi::CString;
use std::io::TempDir;
-use std::c_str::ToCStr;
use std::io::fs::PathExtensions;
use std::io::fs;
use std::io;
let test_file = &old_path.join("temp.txt");
/* Write the temp input file */
- let ostream = test_file.with_c_str(|fromp| {
- "w+b".with_c_str(|modebuf| {
- libc::fopen(fromp, modebuf)
- })
- });
+ let fromp = CString::from_slice(test_file.as_vec());
+ let modebuf = CString::from_slice(b"w+b");
+ let ostream = libc::fopen(fromp.as_ptr(), modebuf.as_ptr());
assert!((ostream as uint != 0u));
let s = "hello".to_string();
- "hello".with_c_str(|buf| {
- let write_len = libc::fwrite(buf as *const libc::c_void,
- 1u as libc::size_t,
- (s.len() + 1u) as libc::size_t,
- ostream);
- assert_eq!(write_len, (s.len() + 1) as libc::size_t)
- });
+ let buf = CString::from_slice(b"hello");
+ let write_len = libc::fwrite(buf.as_ptr() as *mut _,
+ 1u as libc::size_t,
+ (s.len() + 1u) as libc::size_t,
+ ostream);
+ assert_eq!(write_len, (s.len() + 1) as libc::size_t);
assert_eq!(libc::fclose(ostream), (0u as libc::c_int));
let new_path = tmpdir.join_many(&["quux", "blat"]);