ipc.c: Eliminate per-field struct initializations.
authorDaniel Richard G <skunk@iSKUNK.ORG>
Fri, 10 Aug 2012 12:20:57 +0000 (14:20 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 15 Aug 2012 09:39:26 +0000 (11:39 +0200)
This replaces the C99-only initializations in mutex_lock() and
mutex_try_lock() by equivalent but portable code.

ipc.c

diff --git a/ipc.c b/ipc.c
index b9f0405..14b0259 100644 (file)
--- a/ipc.c
+++ b/ipc.c
@@ -283,31 +283,27 @@ static int do_semop(int id, struct sembuf *sops, int num)
 
 static int mutex_lock(int id)
 {
+       struct sembuf sops[4];
        int ret;
 
        DSS_DEBUG_LOG("locking\n");
-       struct sembuf sops[4] = {
-               {
-                       .sem_num = 0,
-                       .sem_op = 0,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               },
-               {
-                       .sem_num = 0,
-                       .sem_op = 1,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               },
-               {
-                       .sem_num = 1,
-                       .sem_op = 0,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               },
-               {
-                       .sem_num = 1,
-                       .sem_op = 1,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               }
-       };
+
+       sops[0].sem_num = 0;
+       sops[0].sem_op = 0;
+       sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+       sops[1].sem_num = 0;
+       sops[1].sem_op = 1;
+       sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+       sops[2].sem_num = 1;
+       sops[2].sem_op = 0;
+       sops[2].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+       sops[3].sem_num = 1;
+       sops[3].sem_op = 1;
+       sops[3].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
        ret = do_semop(id, sops, 4);
        if (ret < 0)
                return -ERRNO_TO_DSS_ERROR(errno);
@@ -316,21 +312,19 @@ static int mutex_lock(int id)
 
 static int mutex_try_lock(int id)
 {
+       struct sembuf sops[2];
        int ret;
 
        DSS_DEBUG_LOG("trying to lock\n");
-       struct sembuf sops[2] = {
-               {
-                       .sem_num = 0,
-                       .sem_op = 0,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               },
-               {
-                       .sem_num = 0,
-                       .sem_op = 1,
-                       .sem_flg = SEM_UNDO | IPC_NOWAIT
-               }
-       };
+
+       sops[0].sem_num = 0;
+       sops[0].sem_op = 0;
+       sops[0].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
+       sops[1].sem_num = 0;
+       sops[1].sem_op = 1;
+       sops[1].sem_flg = SEM_UNDO | IPC_NOWAIT;
+
        ret = do_semop(id, sops, 2);
        if (ret < 0)
                return -ERRNO_TO_DSS_ERROR(errno);