1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
naruse 2016-11-05 15:00:37 +00:00
parent a03411b63e
commit 54a6cd84df
2 changed files with 22 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Sat Nov 5 23:48:27 2016 NARUSE, Yui <naruse@ruby-lang.org>
* file.c (rb_home_dir_of): convert given username into filesystem
encoding. [ruby-core:76682] [Bug #12652]
patched by Dāvis Mosāns
Sat Nov 5 23:46:03 2016 Tanaka Akira <akr@fsij.org>
* time.c (vtm_add_offset): Fix yday on last day of year.

18
file.c
View file

@ -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