diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-26 04:00:28 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-26 04:00:28 +0000 |
commit | 45fbfd0a8197d53678241023798733fb765f9e2a (patch) | |
tree | 2e1cc9b942416e9ea1788a8b7d3a46b8eb7b129a /win32 | |
parent | 8974d5aaa79f42b7366ecd99d74e29d3faf01ab8 (diff) | |
download | ruby-45fbfd0a8197d53678241023798733fb765f9e2a.tar.gz |
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
Diffstat (limited to 'win32')
-rw-r--r-- | win32/file.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/win32/file.c b/win32/file.c index 897f16e9ef..a5aafa5e77 100644 --- a/win32/file.c +++ b/win32/file.c @@ -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]))) { |