summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-08-14 16:25:25 +0100
committerPaul Jakma <paul@quagga.net>2008-08-22 19:52:58 +0100
commitffe11cfb0a808ae514193438616dfabc512b4cf6 (patch)
tree94452dba2c1a49d6e6a0782c6513acb36823cefc /lib
parent9fd4958a4eef88c536e4a5aeefce302e10ee8ee6 (diff)
[lib] hash compare function arguments ought to be const qualified
2008-08-14 Stephen Hemminger <stephen.hemminger@vyatta.com> * lib/hash.h: (struct hash) Hash comparator callback really ought to treat storage behind arguments as constant - a compare function with side-effects would be evil. * */*.c: Adjust comparator functions similarly, thus fixing at least a few compiler warnings about const qualifier being dropped. Signed-off-by: Paul Jakma <paul@quagga.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/distribute.c4
-rw-r--r--lib/hash.c4
-rw-r--r--lib/hash.h6
-rw-r--r--lib/if_rmap.c11
-rw-r--r--lib/thread.c6
5 files changed, 15 insertions, 16 deletions
diff --git a/lib/distribute.c b/lib/distribute.c
index 3d616211..906e3f6d 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -134,7 +134,7 @@ distribute_hash_make (struct distribute *dist)
/* If two distribute-list have same value then return 1 else return
0. This function is used by hash package. */
static int
-distribute_cmp (struct distribute *dist1, struct distribute *dist2)
+distribute_cmp (const struct distribute *dist1, const struct distribute *dist2)
{
if (dist1->ifname && dist2->ifname)
if (strcmp (dist1->ifname, dist2->ifname) == 0)
@@ -769,7 +769,7 @@ void
distribute_list_init (int node)
{
disthash = hash_create ((unsigned int (*) (void *)) distribute_hash_make,
- (int (*) (void *, void *)) distribute_cmp);
+ (int (*) (const void *, const void *)) distribute_cmp);
if(node==RIP_NODE) {
install_element (RIP_NODE, &distribute_list_all_cmd);
diff --git a/lib/hash.c b/lib/hash.c
index 76bf802a..3884051f 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -27,7 +27,7 @@
/* Allocate a new hash. */
struct hash *
hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
- int (*hash_cmp) (void *, void *))
+ int (*hash_cmp) (const void *, const void *))
{
struct hash *hash;
@@ -46,7 +46,7 @@ hash_create_size (unsigned int size, unsigned int (*hash_key) (void *),
/* Allocate a new hash with default hash size. */
struct hash *
hash_create (unsigned int (*hash_key) (void *),
- int (*hash_cmp) (void *, void *))
+ int (*hash_cmp) (const void *, const void *))
{
return hash_create_size (HASHTABSIZE, hash_key, hash_cmp);
}
diff --git a/lib/hash.h b/lib/hash.h
index a6e3d59a..f4b1c23e 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -48,16 +48,16 @@ struct hash
unsigned int (*hash_key) (void *);
/* Data compare function. */
- int (*hash_cmp) (void *, void *);
+ int (*hash_cmp) (const void *, const void *);
/* Backet alloc. */
unsigned long count;
};
extern struct hash *hash_create (unsigned int (*) (void *),
- int (*) (void *, void *));
+ int (*) (const void *, const void *));
extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *),
- int (*) (void *, void *));
+ int (*) (const void *, const void *));
extern void *hash_get (struct hash *, void *, void * (*) (void *));
extern void *hash_alloc_intern (void *);
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index e6f753c2..ddc62fd5 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -120,13 +120,12 @@ if_rmap_hash_make (void *data)
}
static int
-if_rmap_hash_cmp (void *arg1, void* arg2)
+if_rmap_hash_cmp (const void *arg1, const void* arg2)
{
- struct if_rmap *if_rmap1 = arg1;
- struct if_rmap *if_rmap2 = arg2;
- if (strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0)
- return 1;
- return 0;
+ const struct if_rmap *if_rmap1 = arg1;
+ const struct if_rmap *if_rmap2 = arg2;
+
+ return strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0;
}
static struct if_rmap *
diff --git a/lib/thread.c b/lib/thread.c
index 095dff4e..260e8c8e 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -223,8 +223,8 @@ cpu_record_hash_key (struct cpu_thread_history *a)
}
static int
-cpu_record_hash_cmp (struct cpu_thread_history *a,
- struct cpu_thread_history *b)
+cpu_record_hash_cmp (const struct cpu_thread_history *a,
+ const struct cpu_thread_history *b)
{
return a->func == b->func;
}
@@ -410,7 +410,7 @@ thread_master_create ()
if (cpu_record == NULL)
cpu_record
= hash_create_size (1011, (unsigned int (*) (void *))cpu_record_hash_key,
- (int (*) (void *, void *))cpu_record_hash_cmp);
+ (int (*) (const void *, const void *))cpu_record_hash_cmp);
return (struct thread_master *) XCALLOC (MTYPE_THREAD_MASTER,
sizeof (struct thread_master));