summaryrefslogtreecommitdiff
path: root/sbin/dhclient/hash.c
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-02-04 01:18:27 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-02-04 01:18:27 +0000
commitb12ff12eb3ebaff2815c32a57a644eb2e93e8da8 (patch)
treeccf97eb4f75842225541b87484b7b04e22205a78 /sbin/dhclient/hash.c
parent7026ca4195738c3917aa0fa16cfed7db4996fd4b (diff)
8579 lines of KNF, ANSO and zap-junk diff without the resulting binary
changing by a single byte. partly from theo
Diffstat (limited to 'sbin/dhclient/hash.c')
-rw-r--r--sbin/dhclient/hash.c96
1 files changed, 43 insertions, 53 deletions
diff --git a/sbin/dhclient/hash.c b/sbin/dhclient/hash.c
index b4bba2186c9..2ead7f40944 100644
--- a/sbin/dhclient/hash.c
+++ b/sbin/dhclient/hash.c
@@ -42,42 +42,38 @@
#include "dhcpd.h"
-static int do_hash PROTO ((unsigned char *, int, int));
+static int do_hash(unsigned char *, int, int);
-struct hash_table *new_hash ()
+struct hash_table *
+new_hash(void)
{
- struct hash_table *rv = new_hash_table (DEFAULT_HASH_SIZE, "new_hash");
+ struct hash_table *rv = new_hash_table(DEFAULT_HASH_SIZE, "new_hash");
if (!rv)
return rv;
- memset (&rv -> buckets [0], 0,
- DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *));
+ memset(&rv->buckets [0], 0,
+ DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *));
return rv;
}
-static int do_hash (name, len, size)
- unsigned char *name;
- int len;
- int size;
+static int
+do_hash(unsigned char *name, int len, int size)
{
- register int accum = 0;
- register unsigned char *s = name;
+ int accum = 0;
+ unsigned char *s = name;
int i = len;
+
while (i--) {
/* Add the character in... */
accum += *s++;
/* Add carry back in... */
- while (accum > 255) {
+ while (accum > 255)
accum = (accum & 255) + (accum >> 8);
- }
}
- return accum % size;
+ return (accum % size);
}
-void add_hash (table, name, len, pointer)
- struct hash_table *table;
- int len;
- unsigned char *name;
- unsigned char *pointer;
+void add_hash(struct hash_table *table, unsigned char *name, int len,
+ unsigned char *pointer)
{
int hashno;
struct hash_bucket *bp;
@@ -87,24 +83,22 @@ void add_hash (table, name, len, pointer)
if (!len)
len = strlen ((char *)name);
- hashno = do_hash (name, len, table -> hash_count);
- bp = new_hash_bucket ("add_hash");
+ hashno = do_hash(name, len, table->hash_count);
+ bp = new_hash_bucket("add_hash");
if (!bp) {
- warn ("Can't add %s to hash table.", name);
+ warn("Can't add %s to hash table.", name);
return;
}
- bp -> name = name;
- bp -> value = pointer;
- bp -> next = table -> buckets [hashno];
- bp -> len = len;
- table -> buckets [hashno] = bp;
+ bp->name = name;
+ bp->value = pointer;
+ bp->next = table->buckets [hashno];
+ bp->len = len;
+ table->buckets[hashno] = bp;
}
-void delete_hash_entry (table, name, len)
- struct hash_table *table;
- int len;
- unsigned char *name;
+void
+delete_hash_entry(struct hash_table *table, unsigned char *name, int len)
{
int hashno;
struct hash_bucket *bp, *pbp = (struct hash_bucket *)0;
@@ -114,31 +108,27 @@ void delete_hash_entry (table, name, len)
if (!len)
len = strlen ((char *)name);
- hashno = do_hash (name, len, table -> hash_count);
+ hashno = do_hash(name, len, table->hash_count);
/* Go through the list looking for an entry that matches;
if we find it, delete it. */
- for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
- if ((!bp -> len &&
- !strcmp ((char *)bp -> name, (char *)name)) ||
- (bp -> len == len &&
- !memcmp (bp -> name, name, len))) {
- if (pbp) {
- pbp -> next = bp -> next;
- } else {
- table -> buckets [hashno] = bp -> next;
- }
- free_hash_bucket (bp, "delete_hash_entry");
+ for (bp = table->buckets [hashno]; bp; bp = bp->next) {
+ if ((!bp->len &&
+ !strcmp ((char *)bp->name, (char *)name)) ||
+ (bp->len == len && !memcmp (bp->name, name, len))) {
+ if (pbp)
+ pbp->next = bp->next;
+ else
+ table->buckets [hashno] = bp->next;
+ free_hash_bucket(bp, "delete_hash_entry");
break;
}
pbp = bp; /* jwg, 9/6/96 - nice catch! */
}
}
-unsigned char *hash_lookup (table, name, len)
- struct hash_table *table;
- unsigned char *name;
- int len;
+unsigned char *
+hash_lookup (struct hash_table *table, unsigned char *name, int len)
{
int hashno;
struct hash_bucket *bp;
@@ -149,11 +139,11 @@ unsigned char *hash_lookup (table, name, len)
if (!len)
len = strlen ((char *)name);
- hashno = do_hash (name, len, table -> hash_count);
+ hashno = do_hash(name, len, table->hash_count);
- for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
- if (len == bp -> len && !memcmp (bp -> name, name, len))
- return bp -> value;
- }
- return (unsigned char *)0;
+ for (bp = table->buckets [hashno]; bp; bp = bp->next)
+ if (len == bp->len && !memcmp (bp->name, name, len))
+ return bp->value;
+
+ return (NULL);
}