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

win32/file.c: refine convert_mb_to_wchar

* win32/file.c (convert_mb_to_wchar): use bare pointer instead of
  VALUE, and remove useless argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-07-26 04:00:28 +00:00
parent 8974d5aaa7
commit 45fbfd0a81
2 changed files with 17 additions and 8 deletions

View file

@ -1,3 +1,8 @@
Fri Jul 26 13:00:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/file.c (convert_mb_to_wchar): use bare pointer instead of
VALUE, and remove useless argument.
Fri Jul 26 11:42:07 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* rational.c (f_round_common): Rational is expected to be returned by

View file

@ -33,19 +33,17 @@ replace_wchar(wchar_t *s, int find, int replace)
/* Convert str from multibyte char to wchar with specified code page */
static inline void
convert_mb_to_wchar(VALUE str, wchar_t **wstr, wchar_t **wstr_pos, size_t *wstr_len, UINT code_page)
convert_mb_to_wchar(const char *str, wchar_t **wstr, size_t *wstr_len, UINT code_page)
{
size_t len;
if (NIL_P(str))
if (!str)
return;
len = MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, NULL, 0) + 1;
len = MultiByteToWideChar(code_page, 0, str, -1, NULL, 0) + 1;
*wstr = (wchar_t *)xmalloc(len * sizeof(wchar_t));
if (wstr_pos)
*wstr_pos = *wstr;
MultiByteToWideChar(code_page, 0, RSTRING_PTR(str), -1, *wstr, len);
MultiByteToWideChar(code_page, 0, str, -1, *wstr, len);
*wstr_len = len - 2;
}
@ -388,7 +386,10 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
/* convert char * to wchar_t */
convert_mb_to_wchar(path, &wpath, &wpath_pos, &wpath_len, cp);
if (!NIL_P(path)) {
convert_mb_to_wchar(RSTRING_PTR(path), &wpath, &wpath_len, cp);
wpath_pos = wpath;
}
/* determine if we need the user's home directory */
/* expand '~' only if NOT rb_file_absolute_path() where `abs_mode` is 1 */
@ -453,7 +454,10 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
}
/* convert char * to wchar_t */
convert_mb_to_wchar(dir, &wdir, &wdir_pos, &wdir_len, cp);
if (!NIL_P(dir)) {
convert_mb_to_wchar(RSTRING_PTR(dir), &wdir, &wdir_len, cp);
wdir_pos = wdir;
}
if (abs_mode == 0 && wdir_len > 0 && wdir_pos[0] == L'~' &&
(wdir_len == 1 || IS_DIR_SEPARATOR_P(wdir_pos[1]))) {