diff options
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c index eb32b35d43..8ca3dbf979 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -5702,16 +5702,22 @@ rb_chsize(HANDLE h, off_t size) } /* License: Ruby's */ -int -rb_w32_truncate(const char *path, off_t length) +static int +w32_truncate(const char *path, off_t length, UINT cp) { HANDLE h; int ret; - h = CreateFile(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); + WCHAR *wpath; + + if (!(wpath = mbstr_to_wstr(cp, path, -1, NULL))) + return -1; + h = CreateFileW(wpath, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if (h == INVALID_HANDLE_VALUE) { errno = map_errno(GetLastError()); + free(wpath); return -1; } + free(wpath); ret = rb_chsize(h, length); CloseHandle(h); return ret; @@ -5719,6 +5725,20 @@ rb_w32_truncate(const char *path, off_t length) /* License: Ruby's */ int +rb_w32_utruncate(const char *path, off_t length) +{ + return w32_truncate(path, length, CP_UTF8); +} + +/* License: Ruby's */ +int +rb_w32_truncate(const char *path, off_t length) +{ + return w32_truncate(path, length, filecp()); +} + +/* License: Ruby's */ +int rb_w32_ftruncate(int fd, off_t length) { HANDLE h; |