Source code cleanups: Use void * rather than char * in lhash,
[openssl.git] / crypto / lhash / lhash.c
index 70d24351faaf8b6777c3b2f85b4c53d14d940e81..4d025d7ee737910683125a3b16d55a0663d9dc8a 100644 (file)
@@ -56,8 +56,6 @@
  * [including the GNU Public Licence.]
  */
 
-char *lh_version="lhash part of SSLeay/OpenSSL 0.9.1c 23-Dec-1998";
-
 /* Code for dynamic hash table routines
  * Author - Eric Young v 2.0
  *
@@ -99,35 +97,21 @@ char *lh_version="lhash part of SSLeay/OpenSSL 0.9.1c 23-Dec-1998";
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include "crypto.h"
-#include "lhash.h"
+#include <openssl/crypto.h>
+#include <openssl/lhash.h>
+
+const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
 
 #undef MIN_NODES 
 #define MIN_NODES      16
 #define UP_LOAD                (2*LH_LOAD_MULT) /* load times 256  (default 2) */
 #define DOWN_LOAD      (LH_LOAD_MULT)   /* load times 256  (default 1) */
 
-#ifndef NOPROTO
-
-#define P_CP   char *
-#define P_CPP  char *,char *
 static void expand(LHASH *lh);
 static void contract(LHASH *lh);
-static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
-
-#else
+static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
 
-#define        P_CP
-#define P_CPP
-static void expand();
-static void contract();
-static LHASH_NODE **getrn();
-
-#endif
-
-LHASH *lh_new(h, c)
-unsigned long (*h)();
-int (*c)();
+LHASH *lh_new(unsigned long (*h)(), int (*c)())
        {
        LHASH *ret;
        int i;
@@ -170,12 +154,14 @@ err0:
        return(NULL);
        }
 
-void lh_free(lh)
-LHASH *lh;
+void lh_free(LHASH *lh)
        {
        unsigned int i;
        LHASH_NODE *n,*nn;
 
+       if(lh == NULL)
+           return;
+
        for (i=0; i<lh->num_nodes; i++)
                {
                n=lh->b[i];
@@ -190,13 +176,11 @@ LHASH *lh;
        Free((char *)lh);
        }
 
-char *lh_insert(lh, data)
-LHASH *lh;
-char *data;
+void *lh_insert(LHASH *lh, void *data)
        {
        unsigned long hash;
        LHASH_NODE *nn,**rn;
-       char *ret;
+       void *ret;
 
        lh->error=0;
        if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
@@ -230,13 +214,11 @@ char *data;
        return(ret);
        }
 
-char *lh_delete(lh, data)
-LHASH *lh;
-char *data;
+void *lh_delete(LHASH *lh, void *data)
        {
        unsigned long hash;
        LHASH_NODE *nn,**rn;
-       char *ret;
+       void *ret;
 
        lh->error=0;
        rn=getrn(lh,data,&hash);
@@ -263,13 +245,11 @@ char *data;
        return(ret);
        }
 
-char *lh_retrieve(lh, data)
-LHASH *lh;
-char *data;
+void *lh_retrieve(LHASH *lh, void *data)
        {
        unsigned long hash;
        LHASH_NODE **rn;
-       char *ret;
+       void *ret;
 
        lh->error=0;
        rn=getrn(lh,data,&hash);
@@ -287,17 +267,12 @@ char *data;
        return(ret);
        }
 
-void lh_doall(lh, func)
-LHASH *lh;
-void (*func)();
+void lh_doall(LHASH *lh, void (*func)())
        {
        lh_doall_arg(lh,func,NULL);
        }
 
-void lh_doall_arg(lh, func, arg)
-LHASH *lh;
-void (*func)();
-char *arg;
+void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
        {
        int i;
        LHASH_NODE *a,*n;
@@ -318,8 +293,7 @@ char *arg;
                }
        }
 
-static void expand(lh)
-LHASH *lh;
+static void expand(LHASH *lh)
        {
        LHASH_NODE **n,**n1,**n2,*np;
        unsigned int p,i,j;
@@ -355,7 +329,7 @@ LHASH *lh;
        if ((lh->p) >= lh->pmax)
                {
                j=(int)lh->num_alloc_nodes*2;
-               n=(LHASH_NODE **)Realloc((char *)lh->b,
+               n=(LHASH_NODE **)Realloc(lh->b,
                        (unsigned int)sizeof(LHASH_NODE *)*j);
                if (n == NULL)
                        {
@@ -375,8 +349,7 @@ LHASH *lh;
                }
        }
 
-static void contract(lh)
-LHASH *lh;
+static void contract(LHASH *lh)
        {
        LHASH_NODE **n,*n1,*np;
 
@@ -384,7 +357,7 @@ LHASH *lh;
        lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
        if (lh->p == 0)
                {
-               n=(LHASH_NODE **)Realloc((char *)lh->b,
+               n=(LHASH_NODE **)Realloc(lh->b,
                        (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
                if (n == NULL)
                        {
@@ -415,10 +388,7 @@ LHASH *lh;
                }
        }
 
-static LHASH_NODE **getrn(lh, data, rhash)
-LHASH *lh;
-char *data;
-unsigned long *rhash;
+static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
        {
        LHASH_NODE **ret,*n1;
        unsigned long hash,nn;
@@ -453,8 +423,7 @@ unsigned long *rhash;
        }
 
 /*
-static unsigned long lh_strhash(str)
-char *str;
+unsigned long lh_strhash(char *str)
        {
        int i,l;
        unsigned long ret=0;
@@ -472,8 +441,7 @@ char *str;
  * no collisions on /usr/dict/words and it distributes on %2^n quite
  * well, not as good as MD5, but still good.
  */
-unsigned long lh_strhash(c)
-char *c;
+unsigned long lh_strhash(const char *c)
        {
        unsigned long ret=0;
        long n;