Skip to content

Commit

Permalink
Remove node stdin tty hack (#9476)
Browse files Browse the repository at this point in the history
Fixes #6505
  • Loading branch information
sbc100 authored Sep 22, 2019
1 parent f8c04fa commit e2b9254
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/library_tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,15 @@ mergeInto(LibraryManager.library, {
var buf = Buffer.alloc ? Buffer.alloc(BUFSIZE) : new Buffer(BUFSIZE);
var bytesRead = 0;

var isPosixPlatform = (process.platform != 'win32'); // Node doesn't offer a direct check, so test by exclusion

var fd = process.stdin.fd;
if (isPosixPlatform) {
// Linux and Mac cannot use process.stdin.fd (which isn't set up as sync)
var usingDevice = false;
try {
fd = fs.openSync('/dev/stdin', 'r');
usingDevice = true;
} catch (e) {}
}

try {
bytesRead = fs.readSync(fd, buf, 0, BUFSIZE, null);
bytesRead = fs.readSync(process.stdin.fd, buf, 0, BUFSIZE, null);
} catch(e) {
// Cross-platform differences: on Windows, reading EOF throws an exception, but on other OSes,
// reading EOF returns 0. Uniformize behavior by treating the EOF exception to return 0.
if (e.toString().indexOf('EOF') != -1) bytesRead = 0;
else throw e;
}

if (usingDevice) { fs.closeSync(fd); }
if (bytesRead > 0) {
result = buf.slice(0, bytesRead).toString('utf-8');
} else {
Expand Down

0 comments on commit e2b9254

Please sign in to comment.