mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
refactor: rename write functions to print for consistency in cat
This commit is contained in:
committed by
Daniel Hofstetter
parent
df7ae35a21
commit
f22ae8a345
@@ -142,7 +142,7 @@ impl OutputOptions {
|
||||
|
||||
/// We can write fast if we can simply copy the contents of the file to
|
||||
/// stdout, without augmenting the output with e.g. line numbers.
|
||||
fn can_write_fast(&self) -> bool {
|
||||
fn can_print_fast(&self) -> bool {
|
||||
!(self.show_tabs
|
||||
|| self.show_nonprint
|
||||
|| self.show_ends
|
||||
@@ -359,10 +359,10 @@ fn cat_handle<R: FdReadable>(
|
||||
options: &OutputOptions,
|
||||
state: &mut OutputState,
|
||||
) -> CatResult<()> {
|
||||
if options.can_write_fast() {
|
||||
write_fast(handle)
|
||||
if options.can_print_fast() {
|
||||
print_fast(handle)
|
||||
} else {
|
||||
write_lines(handle, options, state)
|
||||
print_lines(handle, options, state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ fn get_input_type(path: &OsString) -> CatResult<InputType> {
|
||||
|
||||
/// Writes handle to stdout with no configuration. This allows a
|
||||
/// simple memory copy.
|
||||
fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
|
||||
fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
|
||||
let stdout = io::stdout();
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
let mut stdout = stdout;
|
||||
@@ -490,12 +490,12 @@ fn write_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
|
||||
}
|
||||
// If we're not on Linux or Android, or the splice() call failed,
|
||||
// fall back on slower writing.
|
||||
write_slow(handle, stdout)
|
||||
print_slow(handle, stdout)
|
||||
}
|
||||
|
||||
#[cfg_attr(any(target_os = "linux", target_os = "android"), inline(never))] // splice fast-path does not require this allocation
|
||||
#[cfg_attr(not(any(target_os = "linux", target_os = "android")), inline)]
|
||||
fn write_slow<R: FdReadable>(handle: &mut InputHandle<R>, stdout: io::Stdout) -> CatResult<()> {
|
||||
fn print_slow<R: FdReadable>(handle: &mut InputHandle<R>, stdout: io::Stdout) -> CatResult<()> {
|
||||
let mut stdout_lock = stdout.lock();
|
||||
let mut buf = [0; 1024 * 64];
|
||||
loop {
|
||||
@@ -524,7 +524,7 @@ fn write_slow<R: FdReadable>(handle: &mut InputHandle<R>, stdout: io::Stdout) ->
|
||||
|
||||
/// Outputs file contents to stdout in a line-by-line fashion,
|
||||
/// propagating any errors that might occur.
|
||||
fn write_lines<R: FdReadable>(
|
||||
fn print_lines<R: FdReadable>(
|
||||
handle: &mut InputHandle<R>,
|
||||
options: &OutputOptions,
|
||||
state: &mut OutputState,
|
||||
|
||||
@@ -486,7 +486,7 @@ fn get_quoted_file_name(
|
||||
|
||||
fn process_token_filesystem(t: &Token, meta: &StatFs, display_name: &str) {
|
||||
match *t {
|
||||
Token::Byte(byte) => write_raw_byte(byte),
|
||||
Token::Byte(byte) => print_raw_byte(byte),
|
||||
Token::Char(c) => print!("{c}"),
|
||||
Token::Directive {
|
||||
flag,
|
||||
@@ -696,7 +696,7 @@ fn print_unsigned_hex(
|
||||
pad_and_print(&s, flags.left, width, padding_char);
|
||||
}
|
||||
|
||||
fn write_raw_byte(byte: u8) {
|
||||
fn print_raw_byte(byte: u8) {
|
||||
std::io::stdout().write_all(&[byte]).unwrap();
|
||||
}
|
||||
|
||||
@@ -1039,7 +1039,7 @@ impl Stater {
|
||||
_: bool,
|
||||
) -> Result<(), i32> {
|
||||
match *t {
|
||||
Token::Byte(byte) => write_raw_byte(byte),
|
||||
Token::Byte(byte) => print_raw_byte(byte),
|
||||
Token::Char(c) => print!("{c}"),
|
||||
|
||||
Token::Directive {
|
||||
|
||||
Reference in New Issue
Block a user