summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 06:35:57 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-10 06:35:57 +0000
commit6dbda00a6237613bba6f49a18920ade38d7ac68c (patch)
tree7dcb902fe3ed6728e603ba182353107c666f6104 /win32
parentd16ff5c412b90b2766be97a5d3d689c5a18528d3 (diff)
downloadruby-6dbda00a6237613bba6f49a18920ade38d7ac68c.tar.gz
merge revision(s) 54887-54889: [Backport #12340]
* 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/branches/ruby_2_2@55347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/win32/win32.c b/win32/win32.c
index eb1818affa..185c683535 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -5205,16 +5205,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;
@@ -5222,6 +5228,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;