diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-02 14:52:37 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-02 14:52:37 -0800 |
commit | 214fbe8e092b88573fcb3cadec886127ec87d701 (patch) | |
tree | 5281206293c7ba2dcb2d98929c37d3ef4130e563 | |
parent | ab74dbd46dad7a726a817f97d9c4a548e657f168 (diff) | |
parent | 6ba1c5d72bcbbbb8a0dd8100384a367a4c3683f4 (diff) |
Merge pull request #883 from MichaelRiss/perrorFix
Perror formatting fix
-rw-r--r-- | src/library.js | 9 | ||||
-rwxr-xr-x | tests/runner.py | 16 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/library.js b/src/library.js index 4d7b397e..7f177441 100644 --- a/src/library.js +++ b/src/library.js @@ -3363,14 +3363,15 @@ LibraryManager.library = { ___setErrNo(ERRNO_CODES.ECHILD); return -1; }, - perror__deps: ['puts', 'putc', 'strerror', '__errno_location'], + perror__deps: ['puts', 'fputs', 'fputc', 'strerror', '__errno_location'], perror: function(s) { // void perror(const char *s); // http://pubs.opengroup.org/onlinepubs/000095399/functions/perror.html + var stdout = {{{ makeGetValue(makeGlobalUse('_stdout'), '0', 'void*') }}}; if (s) { - _puts(s); - _putc(':'.charCodeAt(0)); - _putc(' '.charCodeAt(0)); + _fputs(s, stdout); + _fputc(':'.charCodeAt(0), stdout); + _fputc(' '.charCodeAt(0), stdout); } var errnum = {{{ makeGetValue('___errno_location()', '0', 'i32') }}}; _puts(_strerror(errnum)); diff --git a/tests/runner.py b/tests/runner.py index 1f4f67d7..8b6e54af 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -5085,6 +5085,22 @@ at function.:blag } ''' self.do_run(src, '22 : me and myself 25 1.34\n21 waka 95\n') + + def test_perror(self): + src = r''' + #include <sys/types.h> + #include <sys/stat.h> + #include <fcntl.h> + #include <stdio.h> + + int main( int argc, char** argv ){ + int retval = open( "NonExistingFile", O_RDONLY ); + if( retval == -1 ) + perror( "Cannot open NonExistingFile" ); + return 0; + } + ''' + self.do_run(src, 'Cannot open NonExistingFile: No such file or directory\n') def test_atoX(self): if self.emcc_args is None: return self.skip('requires ta2') |