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:
parent
a03411b63e
commit
54a6cd84df
2 changed files with 22 additions and 2 deletions
|
@ -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>
|
Sat Nov 5 23:46:03 2016 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* time.c (vtm_add_offset): Fix yday on last day of year.
|
* time.c (vtm_add_offset): Fix yday on last day of year.
|
||||||
|
|
18
file.c
18
file.c
|
@ -3185,13 +3185,27 @@ copy_home_path(VALUE result, const char *dir)
|
||||||
VALUE
|
VALUE
|
||||||
rb_home_dir_of(VALUE user, VALUE result)
|
rb_home_dir_of(VALUE user, VALUE result)
|
||||||
{
|
{
|
||||||
const char *dir, *username = RSTRING_PTR(user);
|
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
struct passwd *pwPtr = getpwnam(username);
|
struct passwd *pwPtr;
|
||||||
#else
|
#else
|
||||||
extern char *getlogin(void);
|
extern char *getlogin(void);
|
||||||
const char *pwPtr = 0;
|
const char *pwPtr = 0;
|
||||||
# define endpwent() ((void)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)
|
if (strcasecmp(username, getlogin()) == 0)
|
||||||
dir = pwPtr = getenv("HOME");
|
dir = pwPtr = getenv("HOME");
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue