@@ -6,9 +6,9 @@ use stream_delimit::stream::*;
6
6
use stream_delimit:: converter:: Converter ;
7
7
use std:: io:: { self , Write } ;
8
8
use clap:: ArgMatches ;
9
- use nix:: unistd:: isatty;
10
9
use std:: path:: PathBuf ;
11
10
use protobuf:: descriptor:: FileDescriptorSet ;
11
+ use libc;
12
12
13
13
pub struct CommandRunner {
14
14
descriptors : Vec < FileDescriptorSet > ,
@@ -46,13 +46,8 @@ impl CommandRunner {
46
46
pub fn run_byte ( self , matches : & ArgMatches ) {
47
47
let stdin = io:: stdin ( ) ;
48
48
let mut stdin = stdin. lock ( ) ;
49
- match isatty ( 0 ) {
50
- Ok ( stdin_is_tty) => {
51
- if !stdin_is_tty {
52
- panic ! ( "pq expects input piped from stdin" )
53
- }
54
- }
55
- Err ( e) => panic ! ( "Error checking if stdin is tty: {}" , e) ,
49
+ if unsafe { libc:: isatty ( libc:: STDIN_FILENO ) != 0 } {
50
+ panic ! ( "pq expects input to be piped from stdin" ) ;
56
51
}
57
52
let stream_type = str_to_streamtype ( matches. value_of ( "STREAM" ) . unwrap_or ( "single" ) )
58
53
. expect ( "Couldn't convert str to streamtype" ) ;
@@ -72,10 +67,7 @@ fn decode_or_convert<T: Iterator<Item = Vec<u8>>>(
72
67
let count = value_t ! ( matches, "COUNT" , i32 ) . unwrap_or ( -1 ) ;
73
68
74
69
let stdout = io:: stdout ( ) ;
75
- let out_is_tty = match isatty ( 1 ) {
76
- Ok ( x) => x,
77
- Err ( e) => panic ! ( "Error checking if stdout is tty: {}" , e) ,
78
- } ;
70
+ let out_is_tty = unsafe { libc:: isatty ( libc:: STDOUT_FILENO ) != 0 } ;
79
71
80
72
if let Some ( convert_type) = matches. value_of ( "CONVERT" ) {
81
73
let converter = Converter :: new (
0 commit comments