diff options
author | max99x <max99x@gmail.com> | 2011-08-05 12:51:08 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-08-05 12:51:08 +0300 |
commit | 0953f092e8856f06dd5fdff9bd8f19c4eca91e73 (patch) | |
tree | cb6891d440b5925871379a010ee2a72ef50450c5 | |
parent | 4152db612e327f1f26e8f56fcd134443907ab77f (diff) |
Fixed stdin bugging out after its first buffer is empty;
Fixed fgets() stripping trailing newline;
Added warning about the inability to read binaries from command line.
-rw-r--r-- | src/library.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js index f5559638..69c69745 100644 --- a/src/library.js +++ b/src/library.js @@ -274,6 +274,8 @@ LibraryManager.library = { } else if (typeof read !== 'undefined') { // Command-line. try { + // WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as + // read() will try to parse UTF8. obj.contents = intArrayFromString(read(obj.url), true); } catch (e) { success = false; @@ -293,7 +295,7 @@ LibraryManager.library = { // Default handlers. if (!input) input = function() { - if (!input.cache) { + if (!input.cache || !input.cache.length) { var result; if (window && typeof window.prompt == 'function') { // Browser. @@ -2668,13 +2670,12 @@ LibraryManager.library = { if (!(stream in FS.streams)) return 0; var streamObj = FS.streams[stream]; if (streamObj.error || streamObj.eof) return 0; - for (var i = 0; i < n - 1; i++) { - var byte_ = _fgetc(stream); + var byte_; + for (var i = 0; i < n - 1 && byte_ != '\n'.charCodeAt(0); i++) { + byte_ = _fgetc(stream); if (byte_ == -1) { if (streamObj.error) return 0; else if (streamObj.eof) break; - } else if (byte_ == '\n'.charCodeAt(0)) { - break; } {{{ makeSetValue('s', 'i', 'byte_', 'i8') }}} } |