diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-14 00:56:03 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-04-14 00:56:03 +0000 |
commit | 7dab92fbe82bf08342de760d50705fc6e69ed4c6 (patch) | |
tree | 666caf663c5bb5d8ba01c6c9bc45e769ea8b3f7a /usr.sbin/dhcpd/hash.c | |
parent | a6b493e3f2f38798ea0e774a2c0db071b2bd49cd (diff) |
more crap bites the dust
Diffstat (limited to 'usr.sbin/dhcpd/hash.c')
-rw-r--r-- | usr.sbin/dhcpd/hash.c | 124 |
1 files changed, 58 insertions, 66 deletions
diff --git a/usr.sbin/dhcpd/hash.c b/usr.sbin/dhcpd/hash.c index b4bba2186c9..5e974120d6a 100644 --- a/usr.sbin/dhcpd/hash.c +++ b/usr.sbin/dhcpd/hash.c @@ -1,6 +1,6 @@ -/* hash.c +/* $OpenBSD: hash.c,v 1.2 2004/04/14 00:56:02 henning Exp $ */ - Routines for manipulating hash tables... */ +/* Routines for manipulating hash tables... */ /* * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. @@ -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 *)); - return rv; + return (rv); + 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; @@ -85,75 +81,71 @@ void add_hash (table, name, len, pointer) if (!table) return; if (!len) - len = strlen ((char *)name); + 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; + struct hash_bucket *bp, *pbp = NULL; if (!table) return; if (!len) - len = strlen ((char *)name); - - 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"); + len = strlen((char *)name); + + 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"); 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; if (!table) - return (unsigned char *)0; + return (NULL); if (!len) - len = strlen ((char *)name); + 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); } |