extern crate libc;
+use std::ffi::CString;
use std::io::TempDir;
use std::io::fs::PathExtensions;
use std::io::fs;
let tmpdir = TempDir::new("rename_directory").ok().expect("rename_directory failed");
let tmpdir = tmpdir.path();
- let old_path = tmpdir.join_many(["foo", "bar", "baz"]);
+ let old_path = tmpdir.join_many(&["foo", "bar", "baz"]);
fs::mkdir_recursive(&old_path, io::USER_RWX);
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"]);
+ let new_path = tmpdir.join_many(&["quux", "blat"]);
fs::mkdir_recursive(&new_path, io::USER_RWX);
fs::rename(&old_path, &new_path.join("newdir"));
assert!(new_path.join("newdir").is_dir());
- assert!(new_path.join_many(["newdir", "temp.txt"]).exists());
+ assert!(new_path.join_many(&["newdir", "temp.txt"]).exists());
}
}