forked from mkxp-z/mkxp-z
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinding-mri-win32.h
42 lines (31 loc) · 1.09 KB
/
binding-mri-win32.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef BINDING_MRI_WIN32_H
#define BINDING_MRI_WIN32_H
#include <windows.h>
#include "util/win-consoleutils.h"
// Attempts to set $stdout and $stdin accordingly on Windows. Only
// called when debug mode is on, since that's when the console
// should be active.
void configureWindowsStreams() {
const int stdoutFD = getStdFD(STD_OUTPUT_HANDLE);
// Configure $stdout
if (stdoutFD >= 0) {
VALUE winStdout = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stdoutFD), rb_str_new_cstr("w+"));
rb_gv_set("stdout", winStdout);
}
const int stdinFD = getStdFD(STD_INPUT_HANDLE);
// Configure $stdin
if (stdinFD >= 0) {
VALUE winStdin = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stdinFD), rb_str_new_cstr("r"));
rb_gv_set("stdin", winStdin);
}
const int stderrFD = getStdFD(STD_ERROR_HANDLE);
// Configure $stderr
if (stderrFD >= 0) {
VALUE winStderr = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stderrFD), rb_str_new_cstr("w+"));
rb_gv_set("stderr", winStderr);
}
}
#endif