diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-08 09:51:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-08 09:51:34 +0000 |
commit | f0355ae7078c8539aaec5991411802c6fd055533 (patch) | |
tree | 20100680dbad4c3ccf9247106f4614134ea0a595 /file.c | |
parent | 65bbd0884c3ec76ca9bb1dfa54184957ac2dff79 (diff) |
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.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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; } |