File tree 1 file changed +19
-11
lines changed
1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -65,19 +65,27 @@ static Handle<Value> OpenStdin(const Arguments& args) {
65
65
return scope.Close (Integer::New (STDIN_FILENO));
66
66
}
67
67
68
- static Handle <Value>
69
- IsStdinBlocking (const Arguments& args)
70
- {
71
- HandleScope scope;
72
- return scope.Close (Boolean::New (!isatty (STDIN_FILENO)));
68
+
69
+ static bool IsBlocking (int fd) {
70
+ if (isatty (fd)) return false ;
71
+ struct stat s;
72
+ if (fstat (fd, &s)) {
73
+ perror (" fstat" );
74
+ return true ;
75
+ }
76
+ if (s.st_mode & S_IFSOCK == S_IFSOCK) return false ;
77
+ if (s.st_mode & S_IFIFO == S_IFIFO) return false ;
78
+ return true ;
73
79
}
74
80
75
- static Handle <Value>
76
- IsStdoutBlocking (const Arguments& args)
77
- {
78
- HandleScope scope;
79
- bool tty = isatty (STDOUT_FILENO);
80
- return scope.Close (Boolean::New (!tty));
81
+
82
+ static Handle <Value> IsStdinBlocking (const Arguments& arg) {
83
+ return IsBlocking (STDIN_FILENO) ? True () : False ();
84
+ }
85
+
86
+
87
+ static Handle <Value> IsStdoutBlocking (const Arguments& args) {
88
+ return IsBlocking (STDOUT_FILENO) ? True () : False ();
81
89
}
82
90
83
91
You can’t perform that action at this time.
0 commit comments