diff options
Diffstat (limited to 'win32/file.c')
-rw-r--r-- | win32/file.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/win32/file.c b/win32/file.c index 4a31fe37eb..799810a4ef 100644 --- a/win32/file.c +++ b/win32/file.c @@ -721,6 +721,28 @@ rb_file_load_ok(const char *path) return ret; } +int +rb_freopen(VALUE fname, const char *mode, FILE *file) +{ + WCHAR *wname, wmode[4]; + int e = 0, n = MultiByteToWideChar(CP_ACP, 0, mode, -1, NULL, 0); + if (n > numberof(wmode)) return EINVAL; + MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, numberof(wmode)); + wname = rb_w32_mbstr_to_wstr(CP_UTF8, RSTRING_PTR(fname), + rb_long2int(RSTRING_LEN(fname)), NULL); + RB_GC_GUARD(fname); +#if RUBY_MSVCRT_VERSION < 80 && !defined(HAVE__WFREOPEN_S) + e = _wfreopen(wname, wmode, file) ? 0 : errno; +#else + { + FILE *newfp = 0; + e = _wfreopen_s(&newfp, wname, wmode, file); + } +#endif + xfree(wname); + return e; +} + void Init_w32_codepage(void) { |