summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/dir.c b/dir.c
index abb5295..aed3ecaa 100644
--- a/dir.c
+++ b/dir.c
@@ -12,6 +12,7 @@
**********************************************************************/
#include "internal.h"
+#include "encindex.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -670,6 +671,18 @@ dir_path(VALUE dir)
}
#if defined _WIN32
+static int
+fundamental_encoding_p(rb_encoding *enc)
+{
+ switch (rb_enc_to_index(enc)) {
+ case ENCINDEX_ASCII:
+ case ENCINDEX_US_ASCII:
+ case ENCINDEX_UTF_8:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
# define READDIR(dir, enc) rb_w32_readdir((dir), (enc))
#else
# define READDIR(dir, enc) readdir((dir))
@@ -1212,9 +1225,7 @@ do_opendir(const char *path, int flags, rb_encoding *enc)
DIR *dirp;
#ifdef _WIN32
VALUE tmp = 0;
- if (enc != rb_usascii_encoding() &&
- enc != rb_ascii8bit_encoding() &&
- enc != rb_utf8_encoding()) {
+ if (!fundamental_encoding_p(enc)) {
tmp = rb_enc_str_new(path, strlen(path), enc);
tmp = rb_str_encode_ospath(tmp);
path = RSTRING_PTR(tmp);
@@ -1525,10 +1536,7 @@ replace_real_basename(char *path, long base, rb_encoding *enc, int norm_p, int f
HANDLE h = INVALID_HANDLE_VALUE;
long wlen;
int e = 0;
- if (enc &&
- enc != rb_usascii_encoding() &&
- enc != rb_ascii8bit_encoding() &&
- enc != rb_utf8_encoding()) {
+ if (!fundamental_encoding_p(enc)) {
tmp = rb_enc_str_new_cstr(plainname, enc);
tmp = rb_str_encode_ospath(tmp);
plainname = RSTRING_PTR(tmp);
@@ -2119,8 +2127,10 @@ push_glob(VALUE ary, VALUE str, int flags)
#ifdef __APPLE__
str = rb_str_encode_ospath(str);
#endif
- if (enc == rb_usascii_encoding()) enc = rb_filesystem_encoding();
- if (enc == rb_usascii_encoding()) enc = rb_ascii8bit_encoding();
+ if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII)
+ enc = rb_filesystem_encoding();
+ if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII)
+ enc = rb_ascii8bit_encoding();
flags |= GLOB_VERBOSE;
args.glob.func = push_pattern;
args.glob.value = ary;