summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--configure.ac3
-rw-r--r--src/expand.c23
3 files changed, 19 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 59f81ff..72c9bfd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
 	* Stop using sysexits.h in commandcmd.
 	* Use stat if stat64 does not exist.
 	* Added default implementation of bsearch.
+	* Added getpwhome as a wrapper for getpwnam.
 
 2005-10-26  Herbert Xu <herbert@gondor.apana.org.au>
 
diff --git a/configure.ac b/configure.ac
index bb0e815..bdce1b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,8 @@ dnl Checks for libraries.
 dnl Checks for header files.
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(bsearch mempcpy sigsetmask stpcpy strchrnul strtoimax strtoumax)
+AC_CHECK_FUNCS(bsearch mempcpy getpwnam sigsetmask stpcpy strchrnul strtoimax \
+	       strtoumax)
 
 dnl Check for klibc signal.
 AC_CHECK_FUNC(signal)
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();