aboutsummaryrefslogtreecommitdiffstats
path: root/src/socket_util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-19 10:55:27 -0500
committerMax Kellermann <max@duempel.org>2011-09-21 17:54:44 +0200
commit8176880173f593dc6833bf2ef52eb1c24786a935 (patch)
treeb5f1f9123ec79fdd2258215069eb8a83b387fe1d /src/socket_util.c
parent533a6b0240c10755b9c1e47ab20611f289dac412 (diff)
downloadmpd-8176880173f593dc6833bf2ef52eb1c24786a935.tar.gz
mpd-8176880173f593dc6833bf2ef52eb1c24786a935.tar.xz
mpd-8176880173f593dc6833bf2ef52eb1c24786a935.zip
Simplify setsockopt() casting workaround
On Win32, the third setsockopt parameter has type (char *) while on POSIX systems it is (void *). However, given that it is a no-op cast to go from a char pointer to a void pointer, we can cast to a char pointer (with a possible const modifier) on all platforms and satisfy the compiler. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/socket_util.c')
-rw-r--r--src/socket_util.c22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/socket_util.c b/src/socket_util.c
index 8f36c10cf..e08b60735 100644
--- a/src/socket_util.c
+++ b/src/socket_util.c
@@ -50,9 +50,6 @@ socket_bind_listen(int domain, int type, int protocol,
{
int fd, ret;
const int reuse = 1;
-#ifdef HAVE_STRUCT_UCRED
- int passcred = 1;
-#endif
fd = socket_cloexec_nonblock(domain, type, protocol);
if (fd < 0) {
@@ -61,14 +58,8 @@ socket_bind_listen(int domain, int type, int protocol,
return -1;
}
-#ifdef WIN32
- const char *optval = (const char *)&reuse;
-#else
- const void *optval = &reuse;
-#endif
-
ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
- optval, sizeof(reuse));
+ (const char *) &reuse, sizeof(reuse));
if (ret < 0) {
g_set_error(error, listen_quark(), errno,
"setsockopt() failed: %s", g_strerror(errno));
@@ -93,7 +84,8 @@ socket_bind_listen(int domain, int type, int protocol,
}
#ifdef HAVE_STRUCT_UCRED
- setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &passcred, sizeof(passcred));
+ setsockopt(fd, SOL_SOCKET, SO_PASSCRED,
+ (const char *) &reuse, sizeof(reuse));
#endif
return fd;
@@ -104,12 +96,6 @@ socket_keepalive(int fd)
{
const int reuse = 1;
-#ifdef WIN32
- const char *optval = (const char *)&reuse;
-#else
- const void *optval = &reuse;
-#endif
-
return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
- optval, sizeof(reuse));
+ (const char *)&reuse, sizeof(reuse));
}