aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
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;
}