[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 12/17] fix build on systems w/out pwd.h
From: |
Mike Frysinger |
Subject: |
[Nano-devel] [PATCH 12/17] fix build on systems w/out pwd.h |
Date: |
Tue, 21 Feb 2017 17:04:44 -0500 |
Windows doesn't have *nix style account databases.
---
configure.ac | 2 +-
src/files.c | 15 ++++++++++++++-
src/utils.c | 4 ++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 71389db7410a..fe1141f55a32 100644
--- 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
index 655408db8ab8..d3f82afa9c1e 100644
--- 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
@@ -172,6 +174,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;
@@ -287,6 +290,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. */
@@ -2442,6 +2448,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);
@@ -2454,6 +2461,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);
@@ -2544,12 +2554,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
@@ -2570,6 +2582,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
index 234e8edfb307..d13a1f0934da 100644
--- 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. */
--
2.11.1
- [Nano-devel] [PATCH 00/17 v3] update autotools & add gnulib support, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 06/17] drop isblank/iswblank fallback functions, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 05/17] drop getdelim/getline fallback functions, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 04/17] drop various str fallback functions, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 01/17] configure: require autoconf-2.69/automake-1.14, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 03/17] add support for gnulib, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 08/17] assume getopt_long support is always available, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 07/17] assume regex.h support is always available, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 12/17] fix build on systems w/out pwd.h,
Mike Frysinger <=
- [Nano-devel] [PATCH 09/17] drop glib fallback for snprintf/vsnprintf, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 17/17] pull in sys_wait module from gnulib, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 14/17] pull in lstat module from gnulib, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 13/17] add an explicit test for set_escdelay, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 16/17] handle builds on systems w/out termios.h, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 02/17] gettext: update to 0.18.3 release, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 11/17] pull in glob module from gnulib, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 10/17] drop wchar.h/wctype.h/stdarg.h checks, Mike Frysinger, 2017/02/21
- [Nano-devel] [PATCH 15/17] handle deficient signal systems, Mike Frysinger, 2017/02/21
- Re: [Nano-devel] [PATCH 00/17 v3] update autotools & add gnulib support, Benno Schulenberg, 2017/02/22