зеркало из https://github.com/github/ruby.git
* 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:
Родитель
7f50d69c4a
Коммит
3e5dc499a8
|
@ -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>
|
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
|
* re.c (str_coderange): to avoid function call when the string already
|
||||||
|
|
2
file.c
2
file.c
|
@ -100,6 +100,8 @@ int flock(int, int);
|
||||||
#define lstat(p, s) rb_w32_ulstati64((p), (s))
|
#define lstat(p, s) rb_w32_ulstati64((p), (s))
|
||||||
#undef access
|
#undef access
|
||||||
#define access(p, m) rb_w32_uaccess((p), (m))
|
#define access(p, m) rb_w32_uaccess((p), (m))
|
||||||
|
#undef truncate
|
||||||
|
#define truncate(p, n) rb_w32_utruncate((p), (n))
|
||||||
#undef chmod
|
#undef chmod
|
||||||
#define chmod(p, m) rb_w32_uchmod((p), (m))
|
#define chmod(p, m) rb_w32_uchmod((p), (m))
|
||||||
#undef chown
|
#undef chown
|
||||||
|
|
|
@ -403,8 +403,9 @@ __declspec(dllimport) extern int finite(double);
|
||||||
|
|
||||||
#define SUFFIX
|
#define SUFFIX
|
||||||
|
|
||||||
extern int rb_w32_ftruncate(int fd, 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_truncate(const char *path, off_t length);
|
||||||
|
extern int rb_w32_utruncate(const char *path, off_t length);
|
||||||
|
|
||||||
#undef HAVE_FTRUNCATE
|
#undef HAVE_FTRUNCATE
|
||||||
#define HAVE_FTRUNCATE 1
|
#define HAVE_FTRUNCATE 1
|
||||||
|
|
|
@ -5702,21 +5702,41 @@ rb_chsize(HANDLE h, off_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
int
|
static int
|
||||||
rb_w32_truncate(const char *path, off_t length)
|
w32_truncate(const char *path, off_t length, UINT cp)
|
||||||
{
|
{
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
int ret;
|
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) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
errno = map_errno(GetLastError());
|
errno = map_errno(GetLastError());
|
||||||
|
free(wpath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
free(wpath);
|
||||||
ret = rb_chsize(h, length);
|
ret = rb_chsize(h, length);
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
return ret;
|
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 */
|
/* License: Ruby's */
|
||||||
int
|
int
|
||||||
rb_w32_ftruncate(int fd, off_t length)
|
rb_w32_ftruncate(int fd, off_t length)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче