mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
write -> write_all
This commit is contained in:
parent
d187dc574b
commit
906d3e4ec5
13 changed files with 49 additions and 49 deletions
|
@ -30,7 +30,7 @@ fn main() {
|
|||
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
|
||||
let mut out = File::open_mode(&Path::new(outfile), Truncate, ReadWrite);
|
||||
|
||||
match out.write(main.as_bytes()) {
|
||||
match out.write_all(main.as_bytes()) {
|
||||
Err(e) => panic!("{}", e),
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ fn main() {
|
|||
let mut input = File::open(&Path::new("src/uutils/uutils.rs")).unwrap();
|
||||
let main = input.read_to_string().unwrap().replace("@CRATES@", crates.as_slice()).replace("@UTIL_MAP@", util_map.as_slice());
|
||||
|
||||
match out.write(main.as_bytes()) {
|
||||
match out.write_all(main.as_bytes()) {
|
||||
Err(e) => panic!("{}", e),
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ fn decode(input: &mut Reader, ignore_garbage: bool) {
|
|||
Ok(bytes) => {
|
||||
let mut out = stdout();
|
||||
|
||||
match out.write(bytes.as_slice()) {
|
||||
match out.write_all(bytes.as_slice()) {
|
||||
Ok(_) => {}
|
||||
Err(f) => { crash!(1, "{}", f); }
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
}
|
||||
match in_buf[pos..].iter().position(|c| *c == '\n' as u8) {
|
||||
Some(p) => {
|
||||
writer.write(&in_buf[pos..pos + p]).unwrap();
|
||||
writer.write_all(&in_buf[pos..pos + p]).unwrap();
|
||||
if show_ends {
|
||||
writer.write_u8('$' as u8).unwrap();
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
at_line_start = true;
|
||||
},
|
||||
None => {
|
||||
writer.write(&in_buf[pos..]).unwrap();
|
||||
writer.write_all(&in_buf[pos..]).unwrap();
|
||||
at_line_start = false;
|
||||
break;
|
||||
}
|
||||
|
@ -218,8 +218,8 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
|||
_ => byte,
|
||||
};
|
||||
match byte {
|
||||
0 ... 31 => writer.write(&['^' as u8, byte + 64]),
|
||||
127 => writer.write(&['^' as u8, byte - 64]),
|
||||
0 ... 31 => writer.write_all(&['^' as u8, byte + 64]),
|
||||
127 => writer.write_all(&['^' as u8, byte - 64]),
|
||||
_ => writer.write_u8(byte),
|
||||
}
|
||||
} else {
|
||||
|
@ -238,7 +238,7 @@ fn write_fast(files: Vec<String>) {
|
|||
while let Ok(n) = reader.read(&mut in_buf) {
|
||||
if n == 0 { break }
|
||||
// This interface is completely broken.
|
||||
writer.write(&in_buf[..n]).unwrap();
|
||||
writer.write_all(&in_buf[..n]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl<'a, W: Writer> UnsafeWriter<'a, W> {
|
|||
|
||||
fn flush_buf(&mut self) -> IoResult<()> {
|
||||
if self.pos != 0 {
|
||||
let ret = self.inner.write(&self.buf[..self.pos]);
|
||||
let ret = self.inner.write_all(&self.buf[..self.pos]);
|
||||
self.pos = 0;
|
||||
ret
|
||||
} else {
|
||||
|
@ -301,7 +301,7 @@ impl<'a, W: Writer> UnsafeWriter<'a, W> {
|
|||
|
||||
fn possibly_flush(&mut self) {
|
||||
if self.pos > self.threshold {
|
||||
self.inner.write(&self.buf[..self.pos]).unwrap();
|
||||
self.inner.write_all(&self.buf[..self.pos]).unwrap();
|
||||
self.pos = 0;
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ fn fail() -> ! {
|
|||
}
|
||||
|
||||
impl<'a, W: Writer> Writer for UnsafeWriter<'a, W> {
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
let dst = &mut self.buf[self.pos..];
|
||||
if buf.len() > dst.len() {
|
||||
fail();
|
||||
|
|
|
@ -71,7 +71,7 @@ fn cut_bytes<R: Reader>(reader: R,
|
|||
loop {
|
||||
match buf_read.select(low - cur_pos) {
|
||||
NewlineFound(_) => {
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
continue 'newline
|
||||
}
|
||||
Complete(bytes) => {
|
||||
|
@ -81,7 +81,7 @@ fn cut_bytes<R: Reader>(reader: R,
|
|||
Partial(bytes) => cur_pos += bytes.len(),
|
||||
EndOfFile => {
|
||||
if orig_pos != cur_pos {
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
break 'newline
|
||||
|
@ -92,7 +92,7 @@ fn cut_bytes<R: Reader>(reader: R,
|
|||
match opts.out_delim {
|
||||
Some(ref delim) => {
|
||||
if print_delim {
|
||||
out.write(delim.as_bytes()).unwrap();
|
||||
out.write_all(delim.as_bytes()).unwrap();
|
||||
}
|
||||
print_delim = true;
|
||||
}
|
||||
|
@ -103,21 +103,21 @@ fn cut_bytes<R: Reader>(reader: R,
|
|||
loop {
|
||||
match buf_read.select(high - cur_pos + 1) {
|
||||
NewlineFound(bytes) => {
|
||||
out.write(bytes).unwrap();
|
||||
out.write_all(bytes).unwrap();
|
||||
continue 'newline
|
||||
}
|
||||
Complete(bytes) => {
|
||||
out.write(bytes).unwrap();
|
||||
out.write_all(bytes).unwrap();
|
||||
cur_pos = high + 1;
|
||||
break
|
||||
}
|
||||
Partial(bytes) => {
|
||||
cur_pos += bytes.len();
|
||||
out.write(bytes).unwrap();
|
||||
out.write_all(bytes).unwrap();
|
||||
}
|
||||
EndOfFile => {
|
||||
if cur_pos != low || low == high {
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
break 'newline
|
||||
|
@ -127,7 +127,7 @@ fn cut_bytes<R: Reader>(reader: R,
|
|||
}
|
||||
|
||||
buf_read.consume_line();
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
0
|
||||
|
@ -159,7 +159,7 @@ fn cut_characters<R: Reader>(reader: R,
|
|||
match opts.out_delim {
|
||||
Some(ref delim) => {
|
||||
if print_delim {
|
||||
out.write(delim.as_bytes()).unwrap();
|
||||
out.write_all(delim.as_bytes()).unwrap();
|
||||
}
|
||||
print_delim = true;
|
||||
}
|
||||
|
@ -170,13 +170,13 @@ fn cut_characters<R: Reader>(reader: R,
|
|||
Some((high_idx, _)) => {
|
||||
let segment = &line.as_bytes()[low_idx..high_idx];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
}
|
||||
None => {
|
||||
let bytes = line.as_bytes();
|
||||
let segment = &bytes[low_idx..];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
|
||||
if line.as_bytes()[bytes.len() - 1] == b'\n' {
|
||||
continue 'newline
|
||||
|
@ -186,7 +186,7 @@ fn cut_characters<R: Reader>(reader: R,
|
|||
|
||||
char_pos = high + 1;
|
||||
}
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
0
|
||||
|
@ -261,9 +261,9 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
|||
|
||||
if delim_search.peek().is_none() {
|
||||
if ! only_delimited {
|
||||
out.write(line.as_slice()).unwrap();
|
||||
out.write_all(line.as_slice()).unwrap();
|
||||
if line[line.len() - 1] != b'\n' {
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
|||
Some((high_idx, next_low_idx)) => {
|
||||
let segment = &line[low_idx..high_idx];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
|
||||
print_delim = true;
|
||||
|
||||
|
@ -297,7 +297,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
|||
None => {
|
||||
let segment = &line[low_idx..];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
|
||||
if line[line.len() - 1] == b'\n' {
|
||||
continue 'newline
|
||||
|
@ -308,7 +308,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
|||
}
|
||||
}
|
||||
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
0
|
||||
|
@ -343,9 +343,9 @@ fn cut_fields<R: Reader>(reader: R,
|
|||
|
||||
if delim_search.peek().is_none() {
|
||||
if ! opts.only_delimited {
|
||||
out.write(line.as_slice()).unwrap();
|
||||
out.write_all(line.as_slice()).unwrap();
|
||||
if line[line.len() - 1] != b'\n' {
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,7 +370,7 @@ fn cut_fields<R: Reader>(reader: R,
|
|||
Some((high_idx, next_low_idx)) => {
|
||||
let segment = &line[low_idx..high_idx];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
|
||||
print_delim = true;
|
||||
low_idx = next_low_idx;
|
||||
|
@ -379,7 +379,7 @@ fn cut_fields<R: Reader>(reader: R,
|
|||
None => {
|
||||
let segment = &line[low_idx..line.len()];
|
||||
|
||||
out.write(segment).unwrap();
|
||||
out.write_all(segment).unwrap();
|
||||
|
||||
if line[line.len() - 1] == b'\n' {
|
||||
continue 'newline
|
||||
|
@ -389,7 +389,7 @@ fn cut_fields<R: Reader>(reader: R,
|
|||
}
|
||||
}
|
||||
|
||||
out.write(&[b'\n']).unwrap();
|
||||
out.write_all(&[b'\n']).unwrap();
|
||||
}
|
||||
|
||||
0
|
||||
|
|
|
@ -207,7 +207,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
|||
let mut p_stream = ParagraphStream::new(&fmt_opts, &mut fp);
|
||||
for para_result in p_stream {
|
||||
match para_result {
|
||||
Err(s) => silent_unwrap!(ostream.write(s.as_bytes())),
|
||||
Err(s) => silent_unwrap!(ostream.write_all(s.as_bytes())),
|
||||
Ok(para) => break_lines(¶, &fmt_opts, &mut ostream)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,18 +60,18 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer
|
|||
let p_init_len = w_len +
|
||||
if opts.crown || opts.tagged {
|
||||
// handle "init" portion
|
||||
silent_unwrap!(ostream.write(para.init_str.as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(para.init_str.as_bytes()));
|
||||
para.init_len
|
||||
} else if !para.mail_header {
|
||||
// for non-(crown, tagged) that's the same as a normal indent
|
||||
silent_unwrap!(ostream.write(p_indent.as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(p_indent.as_bytes()));
|
||||
p_indent_len
|
||||
} else {
|
||||
// except that mail headers get no indent at all
|
||||
0
|
||||
};
|
||||
// write first word after writing init
|
||||
silent_unwrap!(ostream.write(w.as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(w.as_bytes()));
|
||||
|
||||
// does this paragraph require uniform spacing?
|
||||
let uniform = para.mail_header || opts.uniform;
|
||||
|
@ -437,16 +437,16 @@ fn slice_if_fresh<'a>(fresh: bool, word: &'a str, start: usize, uniform: bool, n
|
|||
#[inline(always)]
|
||||
fn write_newline(indent: &str, ostream: &mut Box<Writer>) {
|
||||
silent_unwrap!(ostream.write_char('\n'));
|
||||
silent_unwrap!(ostream.write(indent.as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(indent.as_bytes()));
|
||||
}
|
||||
|
||||
// Write the word, along with slen spaces.
|
||||
#[inline(always)]
|
||||
fn write_with_spaces(word: &str, slen: usize, ostream: &mut Box<Writer>) {
|
||||
if slen == 2 {
|
||||
silent_unwrap!(ostream.write(" ".as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(" ".as_bytes()));
|
||||
} else if slen == 1 {
|
||||
silent_unwrap!(ostream.write_char(' '));
|
||||
}
|
||||
silent_unwrap!(ostream.write(word.as_bytes()));
|
||||
silent_unwrap!(ostream.write_all(word.as_bytes()));
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
||||
use std::old_io;
|
||||
use std::old_io as io;
|
||||
use std::old_io::fs::File;
|
||||
use std::old_io::BufferedReader;
|
||||
|
||||
|
|
|
@ -109,9 +109,9 @@ struct NamedWriter {
|
|||
}
|
||||
|
||||
impl Writer for NamedWriter {
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
with_path(&*self.path.clone(), || {
|
||||
let val = self.inner.write(buf);
|
||||
let val = self.inner.write_all(buf);
|
||||
if val.is_err() {
|
||||
self.inner = Box::new(NullWriter) as Box<Writer>;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ fn test_output_multi_files_print_all_chars() {
|
|||
fn test_stdin_squeeze() {
|
||||
let mut process= Command::new(PROGNAME).arg("-A").spawn().unwrap();
|
||||
|
||||
process.stdin.take().unwrap().write(b"\x00\x01\x02").unwrap();
|
||||
process.stdin.take().unwrap().write_all(b"\x00\x01\x02").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
|
@ -37,7 +37,7 @@ fn test_stdin_squeeze() {
|
|||
fn test_stdin_number_non_blank() {
|
||||
let mut process = Command::new(PROGNAME).arg("-b").arg("-").spawn().unwrap();
|
||||
|
||||
process.stdin.take().unwrap().write(b"\na\nb\n\n\nc").unwrap();
|
||||
process.stdin.take().unwrap().write_all(b"\na\nb\n\n\nc").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ fn run_interactive(cmd: &mut Command, input: &[u8])-> CmdResult {
|
|||
let stdin_cfg = process::CreatePipe(true, false);
|
||||
let mut command = cmd.stdin(stdin_cfg).spawn().unwrap();
|
||||
|
||||
command.stdin.as_mut().unwrap().write(input);
|
||||
command.stdin.as_mut().unwrap().write_all(input);
|
||||
|
||||
let prog = command.wait_with_output().unwrap();
|
||||
CmdResult {
|
||||
|
|
|
@ -8,7 +8,7 @@ static PROGNAME: &'static str = "./nl";
|
|||
#[test]
|
||||
fn test_stdin_nonewline() {
|
||||
let mut process = Command::new(PROGNAME).spawn().unwrap();
|
||||
process.stdin.take().unwrap().write(b"No Newline").unwrap();
|
||||
process.stdin.take().unwrap().write_all(b"No Newline").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
|
@ -19,7 +19,7 @@ fn test_stdin_newline() {
|
|||
let mut process = Command::new(PROGNAME).arg("-s").arg("-")
|
||||
.arg("-w").arg("1").spawn().unwrap();
|
||||
|
||||
process.stdin.take().unwrap().write(b"Line One\nLine Two\n").unwrap();
|
||||
process.stdin.take().unwrap().write_all(b"Line One\nLine Two\n").unwrap();
|
||||
let po = process.wait_with_output().unwrap();
|
||||
let out = str::from_utf8(po.output.as_slice()).unwrap();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ fn test_increase_file_size() {
|
|||
#[test]
|
||||
fn test_decrease_file_size() {
|
||||
let mut file = make_file(TFILE2);
|
||||
file.write(b"1234567890").unwrap();
|
||||
file.write_all(b"1234567890").unwrap();
|
||||
if !Command::new(PROGNAME).args(&["--size=-4", TFILE2]).status().unwrap().success() {
|
||||
panic!();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue