Print this page
5910 libnisdb won't build with modern GCC

@@ -18,16 +18,15 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
 /*
+ * Copyright 2015 Gary Mills
  * Copyright (c) 2001 by Sun Microsystems, Inc.
  * All rights reserved.
  */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 #include <stdio.h>
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 #include "db_dictionary_c.h"
 #include "nisdb_rw.h"

@@ -105,12 +104,10 @@
 
 
 int
 __nisdb_rw_readlock_ok(__nisdb_rwlock_t *rw) {
         int             ret;
-        pthread_t       myself = pthread_self();
-        __nisdb_rl_t    *rr;
 
         if (rw == 0)
                 return (EFAULT);
 
         if (rw->destroyed != 0)

@@ -137,12 +134,10 @@
 
 
 int
 __nisdb_rw_force_writelock(__nisdb_rwlock_t *rw) {
         int             ret;
-        pthread_t       myself = pthread_self();
-        __nisdb_rl_t    *rr;
 
         if (rw == 0 || rw->destroyed != 0)
                 return (ESHUTDOWN);
 
         if ((ret = mutex_lock(&rw->mutex)) != 0)

@@ -204,21 +199,21 @@
          * Need to know if we're holding a read lock already, and if
          * all other readers are blocked waiting for the mutex.
          */
         if (rw->reader_count > 0) {
                 if ((rr = find_reader(myself, rw)) != 0) {
-                        if (rr->count)
+                        if (rr->count) {
                                 /*
                                  * We're already holding a read lock, so
                                  * if the number of readers equals the number
                                  * of blocked readers plus one, all other
                                  * readers are blocked.
                                  */
                                 if (rw->reader_count ==
                                                 (rw->reader_blocked + 1))
                                         all_readers_blocked = 1;
-                        else
+                        } else {
                                 /*
                                  * We're not holding a read lock, so the
                                  * number of readers should equal the number
                                  * of blocked readers if all readers are
                                  * blocked.

@@ -225,10 +220,11 @@
                                  */
                                 if (rw->reader_count == rw->reader_blocked)
                                         all_readers_blocked = 1;
                 }
         }
+        }
 
         /* Wait for reader(s) or writer to finish */
         while (1) {
                 /*
                  * We can stop looping if one of the following holds:

@@ -238,12 +234,12 @@
                  *              - One reader, and it's us
                  *              - N readers, but all blocked on the mutex
                  */
                 if (
                         (rw->writer_count == 0 && rw->reader_count == 0) ||
-                        ((rw->writer_count == 0 || rw->writer.id == myself) &&
-                                (rw->reader_count == 0) ||
+                    (((rw->writer_count == 0 || rw->writer.id == myself) &&
+                    (rw->reader_count == 0)) ||
                                 (rw->reader_count == 1 &&
                                         rw->reader.id == myself))) {
                         break;
                 }
                 /*

@@ -646,11 +642,10 @@
 int
 __nisdb_destroy_lock(__nisdb_rwlock_t *rw) {
 
         int             ret;
         pthread_t       myself = pthread_self();
-        __nisdb_rl_t    *rr;
 
 
         if (rw == 0) {
 #ifdef  NISDB_MT_DEBUG
                 abort();

@@ -672,12 +667,12 @@
         /*
          * Only proceed if if there are neither readers nor writers
          * other than this thread. Also, no nested locks may be in
          * effect.
          */
-        if ((rw->writer_count > 0 &&
-                        (rw->writer.id != myself || rw->writer.count != 1) ||
+        if (((rw->writer_count > 0 &&
+            (rw->writer.id != myself || rw->writer.count != 1)) ||
                 (rw->reader_count > 0 &&
                         !(rw->reader_count == 1 && rw->reader.id == myself &&
                                 rw->reader.count == 1))) ||
                 (rw->writer_count > 0 && rw->reader_count > 0)) {
 #ifdef  NISDB_MT_DEBUG