summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-02 14:05:19 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-02 14:05:19 +0000
commit3e5dc499a8b5629154c791f1497b146d102902aa (patch)
tree9dadf379ed1e7fac98615ff693700ec4fe81599c /win32/win32.c
parent7f50d69c4ad64cd5e8cd8193ef1bd71a58b28ee4 (diff)
* win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements new
truncate alternative which accepts UTF-8 path. * file.c (truncate): use above function. [Bug #12340] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c26
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;