summary refs log tree commit diff
path: root/src/expand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expand.c')
-rw-r--r--src/expand.c23
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();