[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: misc/38993: the macros CMSG_DATA &c. should be documented
The following reply was made to PR misc/38993; it has been noted by GNATS.
From: Taylor R Campbell <campbell%mumble.net@localhost>
Subject: Re: misc/38993: the macros CMSG_DATA &c. should be documented
Date: Sun, 3 May 2009 12:40:48 -0400
Except for some slightly confusing example code, the requested man
page has been added and this PR can probably be closed.
I think that the code would be a little clearer if rather than
declaring a union with an array component of dynamic size using sizeof
to refer to the size size, it simply used:
size_t cmsgsize = CMSG_SPACE(sizeof(int));
if ((cmsgbuf = malloc(cmsgsize)) == NULL)
(void)memset(&msg, 0, sizeof(msg));
msg.msg_control = cmsgbuf;
msg.msg_controllen = cmsgsize;
Since the buffer is allocated with malloc, writing a union with a
struct cmsghdr component doesn't add anything to the alignment already
guaranteed by malloc. The union is a vestige of a stack-allocated
buffer, which might without the union be unaligned. The code without
any union is also conciser.
Main Index |
Thread Index |