From a2f9ccd3d2bffc6f72f02acf7fc4813c670a64ed Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 23 Jan 2020 19:55:36 -0500 Subject: [PATCH] deps: uvwasi: cherry-pick 7b5b6f9 Original commit message: 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 Fixes: https://github.com/nodejs/node/issues/31461 PR-URL: https://github.com/nodejs/node/pull/31495 Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: Jiawen Geng Reviewed-By: Rich Trott --- deps/uvwasi/src/uv_mapping.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/deps/uvwasi/src/uv_mapping.c b/deps/uvwasi/src/uv_mapping.c index 297fdf5b75176f..da922de8da68f5 100644 --- a/deps/uvwasi/src/uv_mapping.c +++ b/deps/uvwasi/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); }