aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorHuw Davies <huw@codeweavers.com>2014-04-17 14:02:47 +0100
committerRiku Voipio <riku.voipio@linaro.org>2014-05-02 21:59:27 +0300
commit52b6549442988e0a0819b6b7fb36ded164952a34 (patch)
treeace1c2ec86cfba2dc07bc69d35a7d0d5c30c3600 /linux-user
parent8c0f0a60d48a6f62c20f4ce77dceb82047d3d57f (diff)
downloadqemu-arm-52b6549442988e0a0819b6b7fb36ded164952a34.tar.gz
linux-user: Move if-elses to a switch statement.
This makes adding more message types cleaner. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/syscall.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5203cc4577..52bd0008d9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1242,25 +1242,40 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
- if ((cmsg->cmsg_level == SOL_SOCKET) &&
- (cmsg->cmsg_type == SCM_RIGHTS)) {
- int *fd = (int *)data;
- int *target_fd = (int *)target_data;
- int i, numfds = len / sizeof(int);
+ switch (cmsg->cmsg_level) {
+ case SOL_SOCKET:
+ switch (cmsg->cmsg_type) {
+ case SCM_RIGHTS:
+ {
+ int *fd = (int *)data;
+ int *target_fd = (int *)target_data;
+ int i, numfds = len / sizeof(int);
- for (i = 0; i < numfds; i++)
- target_fd[i] = tswap32(fd[i]);
- } else if ((cmsg->cmsg_level == SOL_SOCKET) &&
- (cmsg->cmsg_type == SO_TIMESTAMP) &&
- (len == sizeof(struct timeval))) {
- /* copy struct timeval to target */
- struct timeval *tv = (struct timeval *)data;
- struct target_timeval *target_tv =
- (struct target_timeval *)target_data;
-
- target_tv->tv_sec = tswapal(tv->tv_sec);
- target_tv->tv_usec = tswapal(tv->tv_usec);
- } else {
+ for (i = 0; i < numfds; i++)
+ target_fd[i] = tswap32(fd[i]);
+ break;
+ }
+ case SO_TIMESTAMP:
+ {
+ struct timeval *tv = (struct timeval *)data;
+ struct target_timeval *target_tv =
+ (struct target_timeval *)target_data;
+
+ if (len != sizeof(struct timeval))
+ goto unimplemented;
+
+ /* copy struct timeval to target */
+ target_tv->tv_sec = tswapal(tv->tv_sec);
+ target_tv->tv_usec = tswapal(tv->tv_usec);
+ break;
+ }
+ default:
+ goto unimplemented;
+ }
+ break;
+
+ default:
+ unimplemented:
gemu_log("Unsupported ancillary data: %d/%d\n",
cmsg->cmsg_level, cmsg->cmsg_type);
memcpy(target_data, data, len);