Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5985:8ae4b8d78a25 HEAD
More union usage to avoid casting.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 13 Jul 2007 05:52:37 +0300 |
parents | 74a6130211c2 |
children | f2b2dc3337cc |
files | src/lib/network.c |
diffstat | 1 files changed, 14 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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_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 @@ 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_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 @@ } /* 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 {