Skip to content

Commit

Permalink
bzip2.rs: replace isatty with rust std::io::IsTerminal
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Nov 12, 2024
1 parent d0b2044 commit cc9a83e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bzip2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(non_upper_case_globals)]

use std::ffi::{c_char, CStr, CString, OsStr};
use std::io::IsTerminal;
use std::mem::zeroed;
use std::path::{Path, PathBuf};
use std::ptr;
Expand All @@ -14,8 +15,8 @@ use libbzip2_rs_sys::{

use libc::{
_exit, close, exit, fclose, fdopen, ferror, fflush, fgetc, fileno, fopen, fprintf, fread,
fwrite, isatty, open, perror, remove, rewind, signal, stat, strcat, strcmp, strlen, strncpy,
ungetc, utimbuf, write, FILE,
fwrite, open, perror, remove, rewind, signal, stat, strcat, strcmp, strlen, strncpy, ungetc,
utimbuf, write, FILE,
};
extern "C" {
static mut stdin: *mut FILE;
Expand Down Expand Up @@ -1219,7 +1220,7 @@ unsafe fn compress(name: *mut c_char) {
SourceMode::I2O => {
inStr = stdin;
outStr = stdout;
if isatty(fileno(stdout)) != 0 {
if std::io::stdout().is_terminal() {
fprintf(
stderr,
b"%s: I won't write compressed data to a terminal.\n\0" as *const u8
Expand All @@ -1242,7 +1243,7 @@ unsafe fn compress(name: *mut c_char) {
b"rb\0" as *const u8 as *const libc::c_char,
);
outStr = stdout;
if isatty(fileno(stdout)) != 0 {
if std::io::stdout().is_terminal() {
fprintf(
stderr,
b"%s: I won't write compressed data to a terminal.\n\0" as *const u8
Expand Down Expand Up @@ -1494,7 +1495,7 @@ unsafe fn uncompress(name: Option<String>) {
SourceMode::I2O => {
inStr = stdin;
outStr = stdout;
if isatty(fileno(stdin)) != 0 {
if std::io::stdin().is_terminal() {
eprint!(
concat!(
"{program_name}: I won't read compressed data from a terminal.\n",
Expand Down Expand Up @@ -1688,7 +1689,7 @@ unsafe fn testf(name: Option<String>) {
}
match srcMode {
SourceMode::I2O => {
if isatty(fileno(stdin)) != 0 {
if std::io::stdin().is_terminal() {
eprintln!(
"{}: I won't read compressed data from a terminal.",
get_program_name().display(),
Expand Down

0 comments on commit cc9a83e

Please sign in to comment.