diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-03-07 13:43:55 +0100 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-13 17:18:44 -0300 |
commit | 33eb031c01a0a918283290884db0e72ea2f587f0 (patch) | |
tree | 8d4f391b439fa6feb0d34fd35e1b2566a28bf755 /src/os/users.c | |
parent | ad77ff53d3ad5f1c4fdf2938bab2c9999df2c82b (diff) | |
download | rneovim-33eb031c01a0a918283290884db0e72ea2f587f0.tar.gz rneovim-33eb031c01a0a918283290884db0e72ea2f587f0.tar.bz2 rneovim-33eb031c01a0a918283290884db0e72ea2f587f0.zip |
refactored part of expand_env_esc() into mch_get_user_directory()
Diffstat (limited to 'src/os/users.c')
-rw-r--r-- | src/os/users.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/os/users.c b/src/os/users.c index fa8971be61..2d33688d97 100644 --- a/src/os/users.c +++ b/src/os/users.c @@ -84,3 +84,25 @@ int mch_get_uname(uid_t uid, char *s, size_t len) return FAIL; // a number is not a name } +/* + * Returns the user directory for the given username. + * The caller has to free() the returned string. + * If the username is not found, NULL is returned. + */ +char *mch_get_user_directory(const char *name) +{ +#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) + struct passwd *pw; + if (name == NULL) { + return NULL; + } + pw = getpwnam(name); + if (pw != NULL) { + // save the string from the static passwd entry into malloced memory + char *user_directory = (char *)vim_strsave((char_u *)pw->pw_dir); + return user_directory; + } +#endif + return NULL; +} + |