aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-08-24 21:00:11 -0700
committerAnthony Pesch <inolen@gmail.com>2013-08-29 12:56:40 -0700
commit4d41dc3fa572f89249749c4b7a37864c99018004 (patch)
treeb120804b12bca7e7cc7c5c8395455d95c04b1241
parentb872b8a299b43df0bcd8150aa4c4836fe6213e6c (diff)
- added stubs for tcgetattr and tcsetattr
- added fixes for tty get_char in the node environment
-rw-r--r--src/library.js31
-rw-r--r--src/library_tty.js11
2 files changed, 40 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js
index 3ba2f56b..f0a4f53a 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5154,6 +5154,37 @@ LibraryManager.library = {
},
// ==========================================================================
+ // termios.h
+ // ==========================================================================
+ tcgetattr: function(fildes, termios_p) {
+ // http://pubs.opengroup.org/onlinepubs/009695399/functions/tcgetattr.html
+ var stream = FS.getStream(fildes);
+ if (!stream) {
+ ___setErrNo(ERRNO_CODES.EBADF);
+ return -1;
+ }
+ if (!stream.tty) {
+ ___setErrNo(ERRNO_CODES.ENOTTY);
+ return -1;
+ }
+ return 0;
+ },
+
+ tcsetattr: function(fildes, optional_actions, termios_p) {
+ // http://pubs.opengroup.org/onlinepubs/7908799/xsh/tcsetattr.html
+ var stream = FS.getStream(fildes);
+ if (!stream) {
+ ___setErrNo(ERRNO_CODES.EBADF);
+ return -1;
+ }
+ if (!stream.tty) {
+ ___setErrNo(ERRNO_CODES.ENOTTY);
+ return -1;
+ }
+ return 0;
+ },
+
+ // ==========================================================================
// time.h
// ==========================================================================
diff --git a/src/library_tty.js b/src/library_tty.js
index 8f44cd07..6b2368e6 100644
--- a/src/library_tty.js
+++ b/src/library_tty.js
@@ -69,14 +69,21 @@ mergeInto(LibraryManager.library, {
// NOTE: This is weird to support stdout and stderr
// overrides in addition to print and printErr overrides.
default_tty_ops: {
+ // get_char has 3 particular return values:
+ // a.) the next character represented as an integer
+ // b.) undefined to signal that no data is currently available
+ // c.) null to signal an EOF
get_char: function(tty) {
if (!tty.input.length) {
var result = null;
if (ENVIRONMENT_IS_NODE) {
- if (process.stdin.destroyed) {
- return undefined;
+ if (process.stdin._readableState && process.stdin._readableState.ended) {
+ return null; // EOF
}
result = process.stdin.read();
+ if (!result) {
+ return undefined; // no data available
+ }
} else if (typeof window != 'undefined' &&
typeof window.prompt == 'function') {
// Browser.