diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-02 14:05:19 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-02 14:05:19 +0000 |
commit | ce64e3623563e1e6b1cdfdecd7c54869a6522248 (patch) | |
tree | 9dadf379ed1e7fac98615ff693700ec4fe81599c | |
parent | 1cb3ff7e8eb10ae10762039a6ff9f7965d4cac69 (diff) | |
download | ruby-ce64e3623563e1e6b1cdfdecd7c54869a6522248.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | include/ruby/win32.h | 5 | ||||
-rw-r--r-- | win32/win32.c | 26 |
4 files changed, 36 insertions, 5 deletions
@@ -1,3 +1,11 @@ +Mon May 2 23:03:42 2016 NAKAMURA Usaku <usa@ruby-lang.org> + + * 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] + Mon May 2 20:59:21 2016 NARUSE, Yui <naruse@ruby-lang.org> * re.c (str_coderange): to avoid function call when the string already @@ -100,6 +100,8 @@ int flock(int, int); #define lstat(p, s) rb_w32_ulstati64((p), (s)) #undef access #define access(p, m) rb_w32_uaccess((p), (m)) +#undef truncate +#define truncate(p, n) rb_w32_utruncate((p), (n)) #undef chmod #define chmod(p, m) rb_w32_uchmod((p), (m)) #undef chown diff --git a/include/ruby/win32.h b/include/ruby/win32.h index 47f68b8cb2..68b8db73e6 100644 --- a/include/ruby/win32.h +++ b/include/ruby/win32.h @@ -403,8 +403,9 @@ __declspec(dllimport) extern int finite(double); #define SUFFIX -extern int rb_w32_ftruncate(int fd, off_t length); -extern int rb_w32_truncate(const char *path, off_t length); +extern int rb_w32_ftruncate(int fd, off_t length); +extern int rb_w32_truncate(const char *path, off_t length); +extern int rb_w32_utruncate(const char *path, off_t length); #undef HAVE_FTRUNCATE #define HAVE_FTRUNCATE 1 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; |