summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index aa83b5ec40..6637dcb9e3 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -5286,6 +5286,29 @@ rb_w32_write(int fd, const void *buf, size_t size)
return ret;
}
+long
+rb_w32_write_console(VALUE str, int fd)
+{
+ static int disable;
+ HANDLE handle;
+ DWORD dwMode, reslen;
+
+ if (disable) return -1L;
+ handle = (HANDLE)_osfhnd(fd);
+ if (!GetConsoleMode(handle, &dwMode) ||
+ !rb_econv_has_convpath_p(rb_enc_name(rb_enc_get(str)), "UTF-16LE"))
+ return -1L;
+
+ str = rb_str_encode(str, rb_enc_from_encoding(rb_enc_find("UTF-16LE")), 0,
+ Qnil);
+ if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str), RSTRING_LEN(str)/2, &reslen, NULL)) {
+ if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
+ disable = TRUE;
+ return -1L;
+ }
+ return (long)reslen;
+}
+
static int
unixtime_to_filetime(time_t time, FILETIME *ft)
{