summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2017-02-23 00:34:45 +0900
committerJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2017-02-23 00:34:45 +0900
commit8328b792861038159b1db5362fabd38134bbe795 (patch)
treefb10f31bc20dc831f29eabe0ebded72fc585f474
parent1b0541c52fa20be241a7e601e7650731741d5797 (diff)
downloadzsh-8328b792861038159b1db5362fabd38134bbe795.tar.gz
zsh-8328b792861038159b1db5362fabd38134bbe795.zip
40604: revert to the old method if getutent() is not available
-rw-r--r--ChangeLog5
-rw-r--r--Src/watch.c26
-rw-r--r--configure.ac2
3 files changed, 28 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index f3879afc3..d3ce452bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-23 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
+
+ * 40604: configure.ac, Src/watch.c: revert to the old method if
+ getutent() is not available
+
2017-02-21 Barton E. Schaefer <schaefer@zsh.org>
* Julien Nicoulaud: 40586:
diff --git a/Src/watch.c b/Src/watch.c
index 6103ef15f..cd7dc643d 100644
--- a/Src/watch.c
+++ b/Src/watch.c
@@ -91,6 +91,9 @@
# define setutent setutxent
# define getutent getutxent
# define endutent endutxent
+# ifndef HAVE_GETUTENT
+# define HAVE_GETUTENT 1
+# endif
# endif
/*
@@ -482,21 +485,32 @@ ucmp(WATCH_STRUCT_UTMP *u, WATCH_STRUCT_UTMP *v)
static int
readwtab(WATCH_STRUCT_UTMP **head, int initial_sz)
{
- WATCH_STRUCT_UTMP *uptr, *tmp;
+ WATCH_STRUCT_UTMP *uptr;
int wtabmax = initial_sz < 2 ? 32 : initial_sz;
int sz = 0;
+# ifdef HAVE_GETUTENT
+ WATCH_STRUCT_UTMP *tmp;
+# else
+ FILE *in;
+# endif
uptr = *head = (WATCH_STRUCT_UTMP *)
zalloc(wtabmax * sizeof(WATCH_STRUCT_UTMP));
+# ifdef HAVE_GETUTENT
setutent();
while ((tmp = getutent()) != NULL) {
+ memcpy(uptr, tmp, sizeof (WATCH_STRUCT_UTMP));
+# else
+ if (!(in = fopen(WATCH_UTMP_FILE, "r")))
+ return 0;
+ while (fread(uptr, sizeof(WATCH_STRUCT_UTMP), 1, in)) {
+# endif
# ifdef USER_PROCESS
- if (tmp->ut_type == USER_PROCESS)
+ if (uptr->ut_type == USER_PROCESS)
# else /* !USER_PROCESS */
- if (tmp->ut_name[0])
+ if (uptr->ut_name[0])
# endif /* !USER_PROCESS */
{
- memcpy(uptr, tmp, sizeof (WATCH_STRUCT_UTMP));
uptr++;
if (++sz == wtabmax) {
uptr = (WATCH_STRUCT_UTMP *)
@@ -512,7 +526,11 @@ readwtab(WATCH_STRUCT_UTMP **head, int initial_sz)
}
}
}
+# ifdef HAVE_GETUTENT
endutent();
+# else
+ fclose(in);
+# endif
if (sz)
qsort((void *) *head, sz, sizeof(WATCH_STRUCT_UTMP),
diff --git a/configure.ac b/configure.ac
index c6ece6709..0551a69f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1325,7 +1325,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
cygwin_conv_path \
nanosleep \
srand_deterministic \
- setutxent getutxent endutxent)
+ setutxent getutxent endutxent getutent)
AC_FUNC_STRCOLL
AH_TEMPLATE([REALPATH_ACCEPTS_NULL],