summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-11 18:13:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-11 18:13:40 +0000
commit0ae6c7f816cbc3ba0cdd97f609b9ffcbf49bf9bb (patch)
treef6edf414d88a0038fc62c09428007a3104a36a51 /file.c
parent23bb4d7898bcafad7b2b46339994b650aef60a42 (diff)
* file.c (file_expand_path): set external encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/file.c b/file.c
index c0ffa766db..b247d834db 100644
--- a/file.c
+++ b/file.c
@@ -2551,6 +2551,11 @@ rb_path_end(const char *path)
buflen = RSTRING_LEN(result),\
pend = p + buflen)
+#define SET_EXTERNAL_ENCODING() (\
+ (void)(extenc || (extenc = rb_default_external_encoding())),\
+ rb_enc_associate(result, extenc),\
+ rb_enc_check(fname, result))
+
static int is_absolute_path(const char*);
static VALUE
@@ -2559,6 +2564,7 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
char *s, *buf, *b, *p, *pend, *root;
long buflen, dirlen;
int tainted;
+ rb_encoding *extenc = 0;
FilePathValue(fname);
s = StringValuePtr(fname);
@@ -2586,6 +2592,7 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
#endif
s++;
tainted = 1;
+ SET_EXTERNAL_ENCODING();
}
else {
#ifdef HAVE_PWD_H
@@ -2641,6 +2648,7 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
BUFCHECK(dirlen > buflen);
strcpy(buf, dir);
free(dir);
+ SET_EXTERNAL_ENCODING();
}
p = chompdirsep(skiproot(buf));
s += 2;
@@ -2660,6 +2668,7 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
BUFCHECK(dirlen > buflen);
strcpy(buf, dir);
free(dir);
+ SET_EXTERNAL_ENCODING();
}
#if defined DOSISH || defined __CYGWIN__
if (isdirsep(*s)) {
@@ -2749,13 +2758,14 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
if (tainted) OBJ_TAINT(result);
rb_str_set_len(result, p - buf);
+ rb_enc_check(fname, result);
return result;
}
VALUE
rb_file_expand_path(VALUE fname, VALUE dname)
{
- return file_expand_path(fname, dname, rb_str_new(0, MAXPATHLEN + 2));
+ return file_expand_path(fname, dname, rb_usascii_str_new(0, MAXPATHLEN + 2));
}
/*