From 660b61a18289f058796a5de0272cc45014f84dbf Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ Date: Tue, 28 Sep 2010 03:40:35 +0200 Subject: [PATCH] WINGs: Do not look static information up every time Signed-off-by: Tamas TEVESZ --- WINGs/findfile.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/WINGs/findfile.c b/WINGs/findfile.c index b5b4348d..28fa2562 100644 --- a/WINGs/findfile.c +++ b/WINGs/findfile.c @@ -35,38 +35,50 @@ char *wgethomedir() { - char *home = getenv("HOME"); + static char *home = NULL; struct passwd *user; + if (home) + return home; + + home = getenv("HOME"); if (home) return home; user = getpwuid(getuid()); if (!user) { werror(_("could not get password entry for UID %i"), getuid()); - return "/"; - } - if (!user->pw_dir) { - return "/"; - } else { - return user->pw_dir; + home = "/"; } + + if (!user->pw_dir) + home = "/"; + else + home = wstrdup(user->pw_dir); + +out: + return home; } static char *getuserhomedir(const char *username) { + static char *home = NULL; struct passwd *user; + if (home) + return home; + user = getpwnam(username); if (!user) { werror(_("could not get password entry for user %s"), username); return NULL; } - if (!user->pw_dir) { - return "/"; - } else { - return user->pw_dir; - } + if (!user->pw_dir) + home = "/"; + else + home = wstrdup(user->pw_dir); + + return home; } char *wexpandpath(char *path)