From 6fd1b08628a8f331e1a344f8b535f30994ac4e7a Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Sat, 29 Oct 2005 16:01:07 +1000 Subject: [EXPAND] Added getpwhome as a wrapper for getpwnam klibc doesn't have and doesn't need getpwnam. This change creates getpwhome which always returns NULL if getpwnam doesn't exist. --- src/expand.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/expand.c b/src/expand.c index d6efdd8..7fdc492 100644 --- a/src/expand.c +++ b/src/expand.c @@ -37,7 +37,9 @@ #include #include #include +#ifdef HAVE_GETPWNAM #include +#endif #include #include #include @@ -175,6 +177,17 @@ esclen(const char *start, const char *p) { } +static inline const char *getpwhome(const char *name) +{ +#ifdef HAVE_GETPWNAM + struct passwd *pw = getpwnam(name); + return pw ? pw->pw_dir : 0; +#else + return 0; +#endif +} + + /* * Expand shell variables and backquotes inside a here document. */ @@ -382,7 +395,6 @@ exptilde(char *startp, char *p, int flag) { char c; char *name; - struct passwd *pw; const char *home; int quotes = flag & QUOTES_ESC; int startloc; @@ -407,14 +419,11 @@ exptilde(char *startp, char *p, int flag) done: *p = '\0'; if (*name == '\0') { - if ((home = lookupvar(homestr)) == NULL) - goto lose; + home = lookupvar(homestr); } else { - if ((pw = getpwnam(name)) == NULL) - goto lose; - home = pw->pw_dir; + home = getpwhome(name); } - if (*home == '\0') + if (!home || !*home) goto lose; *p = c; startloc = expdest - (char *)stackblock(); -- cgit 1.4.1