diff --git a/test/fixtures/wasi/input2.txt b/test/fixtures/wasi/input2.txt new file mode 100644 index 00000000000000..6aadea38006fb0 --- /dev/null +++ b/test/fixtures/wasi/input2.txt @@ -0,0 +1 @@ +hello from input2.txt diff --git a/test/wasi/c/freopen.c b/test/wasi/c/freopen.c new file mode 100644 index 00000000000000..0f47058da2ca95 --- /dev/null +++ b/test/wasi/c/freopen.c @@ -0,0 +1,16 @@ +#include +#include + +int main() { + FILE* file_orig = fopen("/sandbox/input.txt", "r"); + assert(file_orig != NULL); + FILE* file_new = freopen("/sandbox/input2.txt", "r", file_orig); + assert(file_new != NULL); + + int c = fgetc(file_new); + while (c != EOF) { + int wrote = fputc((char)c, stdout); + assert(wrote != EOF); + c = fgetc(file_new); + } +} diff --git a/test/wasi/test-wasi.js b/test/wasi/test-wasi.js index 9c8b2a752778f9..01d5aa8fe5cc28 100644 --- a/test/wasi/test-wasi.js +++ b/test/wasi/test-wasi.js @@ -60,6 +60,7 @@ if (process.argv[2] === 'wasi-child') { runWASI({ test: 'clock_getres' }); runWASI({ test: 'exitcode', exitCode: 120 }); runWASI({ test: 'fd_prestat_get_refresh' }); + runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` }); runWASI({ test: 'getentropy' }); runWASI({ test: 'getrusage' }); runWASI({ test: 'gettimeofday' }); diff --git a/test/wasi/wasm/freopen.wasm b/test/wasi/wasm/freopen.wasm new file mode 100755 index 00000000000000..fb417fbe21fa69 Binary files /dev/null and b/test/wasi/wasm/freopen.wasm differ