dovecot: More union usage to avoid casting.
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jul 13 05:52:43 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/8ae4b8d78a25
changeset: 5985:8ae4b8d78a25
user: Timo Sirainen <tss at iki.fi>
date: Fri Jul 13 05:52:37 2007 +0300
description:
More union usage to avoid casting.
diffstat:
1 file changed, 14 insertions(+), 8 deletions(-)
src/lib/network.c | 22 ++++++++++++++--------
diffs (59 lines):
diff -r 74a6130211c2 -r 8ae4b8d78a25 src/lib/network.c
--- a/src/lib/network.c Fri Jul 13 05:48:54 2007 +0300
+++ b/src/lib/network.c Fri Jul 13 05:52:37 2007 +0300
@@ -186,12 +186,15 @@ int net_connect_ip(const struct ip_addr
int net_connect_unix(const char *path)
{
- struct sockaddr_un sa;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_un un;
+ } sa;
int fd, ret;
memset(&sa, 0, sizeof(sa));
- sa.sun_family = AF_UNIX;
- if (strocpy(sa.sun_path, path, sizeof(sa.sun_path)) < 0) {
+ sa.un.sun_family = AF_UNIX;
+ if (strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
/* too long path */
errno = EINVAL;
return -1;
@@ -207,7 +210,7 @@ int net_connect_unix(const char *path)
net_set_nonblock(fd, TRUE);
/* connect */
- ret = connect(fd, (void *)&sa, sizeof(sa));
+ ret = connect(fd, &sa.sa, sizeof(sa));
if (ret < 0 && errno != EINPROGRESS) {
close_keep_errno(fd);
return -1;
@@ -323,12 +326,15 @@ int net_listen(const struct ip_addr *my_
int net_listen_unix(const char *path, int backlog)
{
- struct sockaddr_un sa;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_un un;
+ } sa;
int fd;
memset(&sa, 0, sizeof(sa));
- sa.sun_family = AF_UNIX;
- if (strocpy(sa.sun_path, path, sizeof(sa.sun_path)) < 0) {
+ sa.un.sun_family = AF_UNIX;
+ if (strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
/* too long path */
errno = EINVAL;
return -1;
@@ -342,7 +348,7 @@ int net_listen_unix(const char *path, in
}
/* bind */
- if (bind(fd, (void *)&sa, sizeof(sa)) < 0) {
+ if (bind(fd, &sa.sa, sizeof(sa)) < 0) {
if (errno != EADDRINUSE)
i_error("bind(%s) failed: %m", path);
} else {
More information about the dovecot-cvs
mailing list