From 48e4d45ccafce55615aa6d053b9301a4db479df7 Mon Sep 17 00:00:00 2001
From: cjihrig <cjihrig@gmail.com>
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 <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
---
 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);
   }