diff options
author | Anthony Pesch <inolen@gmail.com> | 2013-08-28 13:48:12 -0700 |
---|---|---|
committer | Anthony Pesch <inolen@gmail.com> | 2013-08-29 12:57:33 -0700 |
commit | f561db380be29e2db4e49d1196a73292c94c4e66 (patch) | |
tree | 1641747ba58dfbb1e0e8efb55ecd59d28878fea8 /tests/module | |
parent | fe3533636b24c23fb904f3ca94425003c0565177 (diff) |
updated test_stdin to work in SM shell
Diffstat (limited to 'tests/module')
-rw-r--r-- | tests/module/test_stdin.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/tests/module/test_stdin.c b/tests/module/test_stdin.c index ab84fa77..4838d466 100644 --- a/tests/module/test_stdin.c +++ b/tests/module/test_stdin.c @@ -14,31 +14,40 @@ void main_loop(void *arg) char str[10] = {0}; int ret; - if (line == 0) { - ret = fgetc(stdin); - if (ret != EOF) putc(ret, stdout); - if (ret == '\n') line++; - } else if (line > 0) { - ret = scanf("%10s", str); - if (ret > 0) puts(str); - } + errno = 0; + while (errno != EAGAIN) { + if (line == 0) { + ret = fgetc(stdin); + if (ret != EOF) putc(ret, stdout); + if (ret == '\n') line++; + } else if (line > 0) { + ret = scanf("%10s", str); + if (ret > 0) puts(str); + } - if (ferror(stdin) && errno != EAGAIN) { - puts("error"); - exit(EXIT_FAILURE); - } + if (ferror(stdin) && errno != EAGAIN) { + puts("error"); + exit(EXIT_FAILURE); + } - if (feof(stdin)) { - puts("eof"); - exit(EXIT_SUCCESS); - } + if (feof(stdin)) { + puts("eof"); + exit(EXIT_SUCCESS); + } - clearerr(stdin); + clearerr(stdin); + } } int main(int argc, char const *argv[]) { fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + + // SM shell doesn't implement an event loop and therefor doesn't support + // emscripten_set_main_loop. However, its stdin reads are sync so it + // should exit out after calling main_loop once. + main_loop(NULL); + #if EMSCRIPTEN emscripten_set_main_loop(main_loop, 60, 0); #else |