mirror of
https://github.com/ruby/ruby.git
synced 2025-09-18 01:54:00 +02:00
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
This commit is contained in:
parent
d16ff5c412
commit
6dbda00a62
6 changed files with 248 additions and 99 deletions
|
@ -5205,21 +5205,41 @@ 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;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue