fix build on systems without pwd.h
Windows doesn't have *nix style account databases.
Этот коммит содержится в:
родитель
a0fb55235a
Коммит
a9a45f2b55
@ -57,7 +57,7 @@ AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are placed to.])
|
|||||||
|
|
||||||
dnl Checks for header files.
|
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.
|
dnl Checks for options.
|
||||||
|
|
||||||
|
15
src/files.c
15
src/files.c
@ -29,7 +29,9 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
#define LOCKBUFSIZE 8192
|
#define LOCKBUFSIZE 8192
|
||||||
@ -168,6 +170,7 @@ void set_modified(void)
|
|||||||
* Returns 1 on success, and 0 on failure (but continue anyway). */
|
* Returns 1 on success, and 0 on failure (but continue anyway). */
|
||||||
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
|
int write_lockfile(const char *lockfilename, const char *origfilename, bool modified)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
int cflags, fd;
|
int cflags, fd;
|
||||||
FILE *filestream;
|
FILE *filestream;
|
||||||
pid_t mypid;
|
pid_t mypid;
|
||||||
@ -284,6 +287,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
|
|||||||
free_the_data:
|
free_the_data:
|
||||||
free(lockdata);
|
free(lockdata);
|
||||||
return 0;
|
return 0;
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete the lockfile. Return -1 if unsuccessful, and 1 otherwise. */
|
/* Delete the lockfile. Return -1 if unsuccessful, and 1 otherwise. */
|
||||||
@ -2345,6 +2351,7 @@ char *real_dir_from_tilde(const char *buf)
|
|||||||
get_homedir();
|
get_homedir();
|
||||||
tilde_dir = mallocstrcpy(NULL, homedir);
|
tilde_dir = mallocstrcpy(NULL, homedir);
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
const struct passwd *userdata;
|
const struct passwd *userdata;
|
||||||
|
|
||||||
tilde_dir = mallocstrncpy(NULL, buf, i + 1);
|
tilde_dir = mallocstrncpy(NULL, buf, i + 1);
|
||||||
@ -2357,6 +2364,9 @@ char *real_dir_from_tilde(const char *buf)
|
|||||||
endpwent();
|
endpwent();
|
||||||
if (userdata != NULL)
|
if (userdata != NULL)
|
||||||
tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir);
|
tilde_dir = mallocstrcpy(tilde_dir, userdata->pw_dir);
|
||||||
|
#else
|
||||||
|
tilde_dir = strdup("");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = charalloc(strlen(tilde_dir) + strlen(buf + i) + 1);
|
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)
|
size_t buf_len)
|
||||||
{
|
{
|
||||||
char **matches = NULL;
|
char **matches = NULL;
|
||||||
const struct passwd *userdata;
|
|
||||||
|
|
||||||
assert(buf != NULL && num_matches != NULL && buf_len > 0);
|
assert(buf != NULL && num_matches != NULL && buf_len > 0);
|
||||||
|
|
||||||
*num_matches = 0;
|
*num_matches = 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
|
const struct passwd *userdata;
|
||||||
|
|
||||||
while ((userdata = getpwent()) != NULL) {
|
while ((userdata = getpwent()) != NULL) {
|
||||||
if (strncmp(userdata->pw_name, buf + 1, buf_len - 1) == 0) {
|
if (strncmp(userdata->pw_name, buf + 1, buf_len - 1) == 0) {
|
||||||
/* Cool, found a match. Add it to the list. This makes a
|
/* 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();
|
endpwent();
|
||||||
|
#endif
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -36,6 +38,7 @@ void get_homedir(void)
|
|||||||
if (homedir == NULL) {
|
if (homedir == NULL) {
|
||||||
const char *homenv = getenv("HOME");
|
const char *homenv = getenv("HOME");
|
||||||
|
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
/* When HOME isn't set, or when we're root, get the home directory
|
/* When HOME isn't set, or when we're root, get the home directory
|
||||||
* from the password file instead. */
|
* from the password file instead. */
|
||||||
if (homenv == NULL || geteuid() == 0) {
|
if (homenv == NULL || geteuid() == 0) {
|
||||||
@ -44,6 +47,7 @@ void get_homedir(void)
|
|||||||
if (userage != NULL)
|
if (userage != NULL)
|
||||||
homenv = userage->pw_dir;
|
homenv = userage->pw_dir;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Only set homedir if some home directory could be determined,
|
/* Only set homedir if some home directory could be determined,
|
||||||
* otherwise keep homedir NULL. */
|
* otherwise keep homedir NULL. */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user