From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: fix watch implementation (and Re: UTF-8 locales on BSDs do not support collation correctly)
Date: Tue, 21 Feb 2017 23:55:34 +0900 [thread overview]
Message-ID: <9001F45C-404E-4642-91D8-3465019B5736@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20170112220502.GA11170@trex.cs.ovgu.de>
After the commit d3cf881 (worker/40333), watch.c fails to
compile on OpenBSD (worker/40416), simply because
OpenBSD does not have getutent() (nor getutxent()).
We need to use the old way (open/fread/close) to read
the utmp/utmpx file on systems like OpenBSD.
diff --git a/Src/watch.c b/Src/watch.c
index 6103ef1..f033805 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
+# 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 c6ece67..0551a69 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],
prev parent reply other threads:[~2017-02-21 15:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170112064814epcas3p2f3bbccde5a0aa362e32b984f4150b0de@epcas3p2.samsung.com>
2017-01-12 6:46 ` fix watch implementation Jens Elkner
2017-01-12 10:21 ` Peter Stephenson
2017-01-12 22:05 ` Jens Elkner
2017-02-21 14:55 ` Jun T. [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9001F45C-404E-4642-91D8-3465019B5736@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).