diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2005-10-29 16:01:07 +1000 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2005-10-29 16:01:07 +1000 |
commit | 6fd1b08628a8f331e1a344f8b535f30994ac4e7a (patch) | |
tree | 7468d79e290bf33f7ba42e8ea6048e3ebc60e7d7 /src | |
parent | [SYSTEM] Added default implementation of bsearch (diff) | |
download | dash-6fd1b08628a8f331e1a344f8b535f30994ac4e7a.tar.gz dash-6fd1b08628a8f331e1a344f8b535f30994ac4e7a.zip |
[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.
Diffstat (limited to '')
-rw-r--r-- | src/expand.c | 23 |
1 files changed, 16 insertions, 7 deletions
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 <sys/stat.h> #include <dirent.h> #include <unistd.h> +#ifdef HAVE_GETPWNAM #include <pwd.h> +#endif #include <stdlib.h> #include <stdio.h> #include <limits.h> @@ -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(); |