From 6485e16c1b980df2a74e37c9a429c2e768684906 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 16 Dec 2022 12:48:08 -0700 Subject: [PATCH] fix: libuv can return UV_FILE or UV_TTY for FILE_TYPE_CHAR handles When uvwasi is used on Windows, it might be used in non-"ConsoleMode" and the uv_guess_handle() function can return two different values for FILE_TYPE_CHAR because of that difference. --- src/uv_mapping.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/uv_mapping.c b/src/uv_mapping.c index da922de..75405c1 100644 --- a/src/uv_mapping.c +++ b/src/uv_mapping.c @@ -251,8 +251,13 @@ uvwasi_errno_t uvwasi__get_filetype_by_fd(uv_file fd, uvwasi_filetype_t* type) { if (r != 0) { uv_fs_req_cleanup(&req); - /* Windows can't stat a TTY. */ - if (uv_guess_handle(fd) == UV_TTY) { + uv_handle_type guess; + /* + Windows can't stat a FILE_TYPE_CHAR, which is guessed + as UV_TTY in "ConsoleMode" or UV_FILE otherwise. + */ + guess = uv_guess_handle(fd); + if (guess == UV_TTY || guess == UV_FILE) { *type = UVWASI_FILETYPE_CHARACTER_DEVICE; return UVWASI_ESUCCESS; }