diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-05 15:00:37 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-05 15:00:37 +0000 |
commit | 54a6cd84dfb7e4bd6056569b8806017b6a17ea4e (patch) | |
tree | c5ead65e556d9c282381eac5d6c0ab5079fd16fd /file.c | |
parent | a03411b63ef86badb8fe03d14e6443420131717b (diff) | |
download | ruby-54a6cd84dfb7e4bd6056569b8806017b6a17ea4e.tar.gz |
* file.c (rb_home_dir_of): convert given username into filesystem
encoding. [ruby-core:76682] [Bug #12652]
patched by Dāvis Mosāns
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -3185,13 +3185,27 @@ copy_home_path(VALUE result, const char *dir) VALUE rb_home_dir_of(VALUE user, VALUE result) { - const char *dir, *username = RSTRING_PTR(user); #ifdef HAVE_PWD_H - struct passwd *pwPtr = getpwnam(username); + struct passwd *pwPtr; #else extern char *getlogin(void); const char *pwPtr = 0; # define endpwent() ((void)0) +#endif + const char *dir, *username = RSTRING_PTR(user); + rb_encoding *enc = rb_enc_get(user); +#if defined _WIN32 + rb_encoding *fsenc = rb_utf8_encoding(); +#else + rb_encoding *fsenc = rb_filesystem_encoding(); +#endif + if (enc != fsenc) { + dir = username = RSTRING_PTR(rb_str_conv_enc(user, enc, fsenc)); + } + +#ifdef HAVE_PWD_H + pwPtr = getpwnam(username); +#else if (strcasecmp(username, getlogin()) == 0) dir = pwPtr = getenv("HOME"); #endif |