From 9599fa2877ae7d09157d5ea4d33b1894a2486c7c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 11 Apr 2008 18:13:40 +0000 Subject: * file.c (file_expand_path): set external encoding. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'file.c') diff --git a/file.c b/file.c index c0ffa766d..b247d834d 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)); } /* -- cgit