summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-28 07:22:18 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-28 07:22:18 +0000
commit22d5cf92263998d59d524c706b21c054c8ac53d2 (patch)
tree2c591943312b36e8f481b0037e5cf070cc2d5a88 /dir.c
parente269a71eeb2e360c0882b6c8309b80425d90ddd5 (diff)
* win32/{win32.c,dir.h} (rb_w32_uopendir): new API to pass UTF-8 path.
* win32/win32.c (opendir_internal, rb_w32_opendir): extract and merge common part of rb_w32_opendir() and rb_w32_uopendir(). * dir.c (do_opendir, glob_helper): encoding. * dir.c (dir_initialize, do_opendir): convert path to UTF-8 and call rb_w32_uopendir() instead of rb_w32_opendir() on Windows. fixes #4491, reported by Joey Zhou. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index 65bc9a868d..71df5dab98 100644
--- a/dir.c
+++ b/dir.c
@@ -75,6 +75,8 @@ char *strchr(char*,char);
#define mkdir(p, m) rb_w32_umkdir((p), (m))
#undef rmdir
#define rmdir(p) rb_w32_urmdir(p)
+#undef opendir
+#define opendir(p) rb_w32_uopendir(p)
#endif
#define FNM_NOESCAPE 0x01
@@ -402,6 +404,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
}
GlobPathValue(dirname, FALSE);
+ dirname = rb_str_encode_ospath(dirname);
TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dp);
if (dp->dir) closedir(dp->dir);
@@ -1033,9 +1036,20 @@ do_lstat(const char *path, struct stat *pst, int flags)
}
static DIR *
-do_opendir(const char *path, int flags)
+do_opendir(const char *path, int flags, rb_encoding *enc)
{
- DIR *dirp = opendir(path);
+ DIR *dirp;
+#ifdef _WIN32
+ volatile VALUE tmp;
+ if (enc != rb_usascii_encoding() &&
+ enc != rb_ascii8bit_encoding() &&
+ enc != rb_utf8_encoding()) {
+ tmp = rb_enc_str_new(path, strlen(path), enc);
+ tmp = rb_str_encode_ospath(tmp);
+ path = RSTRING_PTR(tmp);
+ }
+#endif
+ dirp = opendir(path);
if (dirp == NULL && !to_be_ignored(errno))
sys_warning(path);
@@ -1354,7 +1368,7 @@ glob_helper(
struct dirent *dp;
DIR *dirp;
IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
- dirp = do_opendir(*path ? path : ".", flags);
+ dirp = do_opendir(*path ? path : ".", flags, enc);
if (dirp == NULL) return 0;
while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) {