Remove usage of io::FILE_writer
This commit is contained in:
parent
b07ab1fe4b
commit
ff95904c48
@ -1233,14 +1233,6 @@ fn get_type(&self) -> WriterType {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
|
||||
if cleanup {
|
||||
@Wrapper { base: f, cleanup: FILERes::new(f) } as @Writer
|
||||
} else {
|
||||
@f as @Writer
|
||||
}
|
||||
}
|
||||
|
||||
impl Writer for fd_t {
|
||||
fn write(&self, v: &[u8]) {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
@ -1618,25 +1610,6 @@ pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
|
||||
mk_file_writer(path, flags).and_then(|w| Ok(w))
|
||||
}
|
||||
|
||||
|
||||
// FIXME: fileflags // #2004
|
||||
pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
|
||||
unsafe {
|
||||
let f = do path.with_c_str |pathbuf| {
|
||||
do "w".with_c_str |modebuf| {
|
||||
libc::fopen(pathbuf, modebuf)
|
||||
}
|
||||
};
|
||||
return if f as uint == 0u {
|
||||
Err(~"error opening " + path.to_str())
|
||||
} else {
|
||||
Ok(FILE_writer(f, true))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME (#2004) it would be great if this could be a const
|
||||
// FIXME (#2004) why are these different from the way stdin() is
|
||||
// implemented?
|
||||
@ -2086,16 +2059,6 @@ fn file_writer_bad_name() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffered_file_writer_bad_name() {
|
||||
match io::buffered_file_writer(&Path("?/?")) {
|
||||
Err(e) => {
|
||||
assert!(e.starts_with("error opening"));
|
||||
}
|
||||
Ok(_) => fail2!()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes_buffer_overwrite() {
|
||||
let wr = BytesWriter::new();
|
||||
|
@ -307,7 +307,6 @@ pub fn process_output(prog: &str, args: &[~str]) -> ProcessOutput {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use io;
|
||||
use libc::c_int;
|
||||
use option::{Option, None, Some};
|
||||
use os;
|
||||
@ -315,6 +314,8 @@ mod tests {
|
||||
use run;
|
||||
use str;
|
||||
use unstable::running_on_valgrind;
|
||||
use rt::io::native::file;
|
||||
use rt::io::{Writer, Reader};
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os="android"))]
|
||||
@ -412,21 +413,21 @@ fn test_pipes() {
|
||||
}
|
||||
|
||||
fn writeclose(fd: c_int, s: &str) {
|
||||
let writer = io::fd_writer(fd, false);
|
||||
writer.write_str(s);
|
||||
os::close(fd);
|
||||
let mut writer = file::FileDesc::new(fd);
|
||||
writer.write(s.as_bytes());
|
||||
}
|
||||
|
||||
fn readclose(fd: c_int) -> ~str {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
|
||||
unsafe {
|
||||
let file = os::fdopen(fd);
|
||||
let reader = io::FILE_reader(file, false);
|
||||
let buf = reader.read_whole_stream();
|
||||
os::fclose(file);
|
||||
str::from_utf8(buf)
|
||||
let mut res = ~[];
|
||||
let mut reader = file::FileDesc::new(fd);
|
||||
let mut buf = [0, ..1024];
|
||||
loop {
|
||||
match reader.read(buf) {
|
||||
Some(n) => { res.push_all(buf.slice_to(n)); }
|
||||
None => break
|
||||
}
|
||||
}
|
||||
str::from_utf8_owned(res)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user