summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 04:00:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-26 04:00:28 +0000
commit45fbfd0a8197d53678241023798733fb765f9e2a (patch)
tree2e1cc9b942416e9ea1788a8b7d3a46b8eb7b129a
parent8974d5aaa79f42b7366ecd99d74e29d3faf01ab8 (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--win32/file.c20
2 files changed, 17 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d01e4ce2e..8e4ce09739 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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]))) {