From e3f4a08522b10ce0a39f41bbfa4f1ef5ad06daca Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 23 Jan 2020 19:55:36 -0500 Subject: [PATCH] allow windows to detect tty types uv_fs_fstat() fails on TTYs on Windows. This commit updates uvwasi__get_filetype_by_fd() to detect this case and map the fd to the WASI character device type. Refs: https://github.com/nodejs/node/issues/31461 --- src/uv_mapping.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/uv_mapping.c b/src/uv_mapping.c index 297fdf5..da922de 100644 --- a/src/uv_mapping.c +++ b/src/uv_mapping.c @@ -249,8 +249,15 @@ uvwasi_errno_t uvwasi__get_filetype_by_fd(uv_file fd, uvwasi_filetype_t* type) { r = uv_fs_fstat(NULL, &req, fd, NULL); if (r != 0) { - *type = UVWASI_FILETYPE_UNKNOWN; uv_fs_req_cleanup(&req); + + /* Windows can't stat a TTY. */ + if (uv_guess_handle(fd) == UV_TTY) { + *type = UVWASI_FILETYPE_CHARACTER_DEVICE; + return UVWASI_ESUCCESS; + } + + *type = UVWASI_FILETYPE_UNKNOWN; return uvwasi__translate_uv_error(r); }