emscripten
emscripten copied to clipboard
When I use fflush(stdin), the output is wrong. Is it a bug?
Source code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
int a,b;
while( scanf("%d %d",&a,&b)!=EOF){
fflush(stdin);
printf("%d %d\n", a, b);
}
return 0;
}
In input.txt:
1 2
3 4
5 6
Run with "wasmtime a.wasm < input.txt" or "wasmer a.wasm < input.txt", the output is:
1 2
Is it a bug?
Looks like probably an emscripten bug yes. Something to do with the stdin handling most likely.
You can repro this without wasmtime or wasmer:
$ emcc test.c
node ./a.out.js < input.txt
1 2
Surprisingly it also occurs with -sNODERAWFS which normally bypasses any bugs in the emscripten FS layers.