1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
usa 2016-05-02 14:05:19 +00:00
parent 7f50d69c4a
commit 3e5dc499a8
4 changed files with 36 additions and 5 deletions

View file

@ -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

2
file.c
View file

@ -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

View file

@ -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

View file

@ -5702,21 +5702,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)