ruby-changes:42815
From: usa <ko1@a...>
Date: Mon, 2 May 2016 22:08:43 +0900 (JST)
Subject: [ruby-changes:42815] usa:r54889 (trunk): * win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements new
usa 2016-05-02 23:05:19 +0900 (Mon, 02 May 2016) New Revision: 54889 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54889 Log: * 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] Modified files: trunk/ChangeLog trunk/file.c trunk/include/ruby/win32.h trunk/win32/win32.c Index: win32/win32.c =================================================================== --- win32/win32.c (revision 54888) +++ win32/win32.c (revision 54889) @@ -5702,22 +5702,42 @@ rb_chsize(HANDLE h, off_t size) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5702 } /* 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; } /* 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) { Index: ChangeLog =================================================================== --- ChangeLog (revision 54888) +++ ChangeLog (revision 54889) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon May 2 23:03:42 2016 NAKAMURA Usaku <usa@r...> + + * 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@r...> * re.c (str_coderange): to avoid function call when the string already Index: include/ruby/win32.h =================================================================== --- include/ruby/win32.h (revision 54888) +++ include/ruby/win32.h (revision 54889) @@ -403,8 +403,9 @@ __declspec(dllimport) extern int finite( https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L403 #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 Index: file.c =================================================================== --- file.c (revision 54888) +++ file.c (revision 54889) @@ -100,6 +100,8 @@ int flock(int, int); https://github.com/ruby/ruby/blob/trunk/file.c#L100 #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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/