aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-08 09:51:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-08 09:51:34 +0000
commit49c801628238b3eb8af2e6dc33b4d4af412b2d87 (patch)
tree20100680dbad4c3ccf9247106f4614134ea0a595 /file.c
parent73cf76e5dc515e0e5eb76695145a53883d3b5113 (diff)
downloadruby-49c801628238b3eb8af2e6dc33b4d4af412b2d87.tar.gz
file.c: home dir fall back
* file.c (rb_home_dir_of): return the default home path if the user name is the current user name, on platforms where struct pwd is not supported. a temporary measure against [Bug #12226]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/file.c b/file.c
index fab1b343c1..cc12c650ca 100644
--- a/file.c
+++ b/file.c
@@ -3178,17 +3178,25 @@ 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(RSTRING_PTR(user));
+ struct passwd *pwPtr = getpwnam(username);
+#else
+ extern char *getlogin(void);
+ const char *pwPtr = 0;
+ # define endpwent() ((void)0)
+ if (strcasecmp(username, getlogin()) == 0)
+ dir = pwPtr = getenv("HOME");
+#endif
if (!pwPtr) {
endpwent();
-#endif
rb_raise(rb_eArgError, "user %"PRIsVALUE" doesn't exist", user);
-#ifdef HAVE_PWD_H
}
- copy_home_path(result, pwPtr->pw_dir);
- endpwent();
+#ifdef HAVE_PWD_H
+ dir = pwPtr->pw_dir;
#endif
+ copy_home_path(result, dir);
+ endpwent();
return result;
}