summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-18 10:36:20 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-18 10:36:20 +0000
commit3f0ec8887f3bc75a98fd3ec8926518b635c70b7b (patch)
treecd0f721ca0e03ccec39353962869b9a6e8477c93 /dir.c
parent88aa8632741d027d1d2e58f8073d4ec90845499d (diff)
* string.c (rb_external_str_new): a new function to convert from
external encoding to internal encoding. if something went wrong, it returns a string with the external encoding. * string.c (rb_external_str_new_with_enc): same as above besides you can specify the source encoding. * ruby.c (ruby_set_argv): use rb_external_str_new() * ruby.c (set_arg0, ruby_script): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/dir.c b/dir.c
index dd98b878cd..3de4c290be 100644
--- a/dir.c
+++ b/dir.c
@@ -423,16 +423,6 @@ dir_check(VALUE dir)
if (dirp->dir == NULL) dir_closed();\
} while (0)
-static VALUE
-dir_enc_str_new(const char *p, long len, rb_encoding *enc)
-{
- VALUE path = rb_tainted_str_new(p, len);
- if (rb_enc_asciicompat(enc) && rb_enc_str_asciionly_p(path)) {
- enc = rb_usascii_encoding();
- }
- rb_enc_associate(path, enc);
- return path;
-}
/*
* call-seq:
@@ -494,7 +484,7 @@ dir_read(VALUE dir)
errno = 0;
dp = readdir(dirp->dir);
if (dp) {
- return dir_enc_str_new(dp->d_name, NAMLEN(dp), dirp->enc);
+ return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
}
else if (errno == 0) { /* end of stream */
return Qnil;
@@ -532,7 +522,7 @@ dir_each(VALUE dir)
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
- rb_yield(dir_enc_str_new(dp->d_name, NAMLEN(dp), dirp->enc));
+ rb_yield(rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc));
if (dirp->dir == NULL) dir_closed();
}
return dir;
@@ -1436,7 +1426,7 @@ rb_glob(const char *path, void (*func)(const char *, VALUE, void *), VALUE arg)
static void
push_pattern(const char *path, VALUE ary, void *enc)
{
- rb_ary_push(ary, dir_enc_str_new(path, strlen(path), enc));
+ rb_ary_push(ary, rb_external_str_new_with_enc(path, strlen(path), enc));
}
static int