[PATCH:xdm 1/2] Add a cast to avoid a compiler error.
Thomas Klausner
wiz at netbsd.org
Sat Jun 29 07:52:50 PDT 2013
On Sat, Jun 29, 2013 at 04:12:40PM +0200, Geert Uytterhoeven wrote:
> > static ssize_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
> > +static ssize_t voidwrite(int, void *, size_t);
>
> If you put the body here (is that allowed by xorg coding style?), you don't
> even need a forward declaration.
I don't know, that's why I went the safe route. But you can have it
that way too.
> >
> > #ifndef offsetof
> > # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
> > @@ -188,3 +189,9 @@ atomicio(ssize_t (*f)(int, void *, size_t), int fd, void *_s, size_t n)
> > }
> > return (pos);
> > }
> > +
> > +static ssize_t
> > +voidwrite(int d, void *buf, size_t nbytes)
> > +{
> > + return write(d, (const char *)buf, nbytes);
>
> And now even the cast can be removed, as a "void *" can be passed where a
> "const void *" is expected.
Ok. Can you merge it now, please?
Attached.
Thomas
-------------- next part --------------
>From 041605d14089b0a6154fa63eaf8b005523f91af6 Mon Sep 17 00:00:00 2001
From: Thomas Klausner <wiz at NetBSD.org>
Date: Sun, 2 Jun 2013 22:20:41 +0200
Subject: [PATCH:xdm 2/2] Add wrapper function for write.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
gcc-4.5.4 on NetBSD complains:
xdm/prngc.c: In function ?get_prngd_bytes?:
xdm/prngc.c:133:2: error: passing argument 1 of ?atomicio? from incompatible pointer type
xdm/prngc.c:46:16: note: expected ?ssize_t (*)(int, void *, size_t)? but argument is of type ?ssize_t (*)(int, const void *, size_t)?
The problem is that the read(2) and write(2) syscalls differ
in the const-ness of their second argument. The wrapper
function gets rid of the difference.
Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
---
xdm/prngc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/xdm/prngc.c b/xdm/prngc.c
index f0db8eb..c1a89bc 100644
--- a/xdm/prngc.c
+++ b/xdm/prngc.c
@@ -45,6 +45,12 @@
static ssize_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
+static ssize_t
+voidwrite(int d, void *buf, size_t nbytes)
+{
+ return write(d, buf, nbytes);
+}
+
#ifndef offsetof
# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
@@ -130,7 +136,7 @@ reopen:
msg[0] = 0x02;
msg[1] = len;
- if (atomicio(write, fd, msg, sizeof(msg)) != sizeof(msg)) {
+ if (atomicio(voidwrite, fd, msg, sizeof(msg)) != sizeof(msg)) {
if (errno == EPIPE && errors < 10) {
close(fd);
errors++;
--
1.8.3.1
More information about the xorg-devel
mailing list