commit a9a45f2b558b80607491119869d52d8e6a080294
parent a0fb55235a7a4829aaab55ed5fc8460ebd578e6f
Author: Mike Frysinger <vapier@gentoo.org>
Date: Tue, 21 Feb 2017 17:04:44 -0500
fix build on systems without pwd.h
Windows doesn't have *nix style account databases.
Diffstat:
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -57,7 +57,7 @@ AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are placed to.])
dnl Checks for header files.
-AC_CHECK_HEADERS(libintl.h limits.h sys/param.h)
+AC_CHECK_HEADERS(libintl.h limits.h pwd.h sys/param.h)
dnl Checks for options.
diff --git a/src/files.c b/src/files.c
@@ -29,7 +29,9 @@
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
+#ifdef HAVE_PWD_H
#include <pwd.h>
+#endif
#include <libgen.h>
#define LOCKBUFSIZE 8192
@@ -168,6 +170,7 @@ void set_modified(void)
* Returns 1 on success, and 0 on failure (but continue anyway). */
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
{
+#ifdef HAVE_PWD_H
int cflags, fd;
FILE *filestream;
pid_t mypid;
@@ -284,6 +287,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
free_the_data:
free(lockdata);
return 0;
+#else
+ return 1;
+#endif
}
/* Delete the lockfile. Return -1 if unsuccessful, and 1 otherwise. */
@@ -2345,6 +2351,7 @@ char *real_dir_from_tilde(const char *buf)
get_homedir();
tilde_dir = mallocstrcpy(NULL, homedir);
} else {
+#ifdef HAVE_PWD_H
const struct passwd *userdata;
tilde_dir = mallocstrncpy(NULL, buf, i + 1);
@@ -2357,6 +2364,9 @@ char *real_dir_from_tilde(const char *buf)
endpwent();
if (userdata != NULL)
tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir);
+#else
+ tilde_dir = strdup("");
+#endif
}
retval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1);
@@ -2447,12 +2457,14 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
size_t buf_len)
{
char **matches = NULL;
- const struct passwd *userdata;
assert(buf != NULL && num_matches != NULL && buf_len > 0);
*num_matches = 0;
+#ifdef HAVE_PWD_H
+ const struct passwd *userdata;
+
while ((userdata = getpwent()) != NULL) {
if (strncmp(userdata->pw_name, buf + 1, buf_len - 1) == 0) {
/* Cool, found a match. Add it to the list. This makes a
@@ -2473,6 +2485,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
}
}
endpwent();
+#endif
return matches;
}
diff --git a/src/utils.c b/src/utils.c
@@ -25,7 +25,9 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#ifdef HAVE_PWD_H
#include <pwd.h>
+#endif
#include <ctype.h>
#include <errno.h>
@@ -36,6 +38,7 @@ void get_homedir(void)
if (homedir == NULL) {
const char *homenv = getenv("HOME");
+#ifdef HAVE_PWD_H
/* When HOME isn't set, or when we're root, get the home directory
* from the password file instead. */
if (homenv == NULL || geteuid() == 0) {
@@ -44,6 +47,7 @@ void get_homedir(void)
if (userage != NULL)
homenv = userage->pw_dir;
}
+#endif
/* Only set homedir if some home directory could be determined,
* otherwise keep homedir NULL. */