summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/lhash/lhash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.c')
-rw-r--r--src/lib/libcrypto/lhash/lhash.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
index 801322beb6..6a340a2403 100644
--- a/src/lib/libcrypto/lhash/lhash.c
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -64,11 +64,11 @@
64 * 64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98 65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 * 66 *
67 * 2.0 eay - Fixed a bug that occured when using lh_delete 67 * 2.0 eay - Fixed a bug that occurred when using lh_delete
68 * from inside lh_doall(). As entries were deleted, 68 * from inside lh_doall(). As entries were deleted,
69 * the 'table' was 'contract()ed', making some entries 69 * the 'table' was 'contract()ed', making some entries
70 * jump from the end of the table to the start, there by 70 * jump from the end of the table to the start, there by
71 * skiping the lh_doall() processing. eay - 4/12/95 71 * skipping the lh_doall() processing. eay - 4/12/95
72 * 72 *
73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs 73 * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs
74 * were not being free()ed. 21/11/95 74 * were not being free()ed. 21/11/95
@@ -107,12 +107,9 @@ const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ 107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ 108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
109 109
110
111#define P_CP char *
112#define P_CPP char *,char *
113static void expand(LHASH *lh); 110static void expand(LHASH *lh);
114static void contract(LHASH *lh); 111static void contract(LHASH *lh);
115static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash); 112static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
116 113
117LHASH *lh_new(unsigned long (*h)(), int (*c)()) 114LHASH *lh_new(unsigned long (*h)(), int (*c)())
118 { 115 {
@@ -152,7 +149,7 @@ LHASH *lh_new(unsigned long (*h)(), int (*c)())
152 ret->error=0; 149 ret->error=0;
153 return(ret); 150 return(ret);
154err1: 151err1:
155 Free((char *)ret); 152 Free(ret);
156err0: 153err0:
157 return(NULL); 154 return(NULL);
158 } 155 }
@@ -175,15 +172,15 @@ void lh_free(LHASH *lh)
175 n=nn; 172 n=nn;
176 } 173 }
177 } 174 }
178 Free((char *)lh->b); 175 Free(lh->b);
179 Free((char *)lh); 176 Free(lh);
180 } 177 }
181 178
182char *lh_insert(LHASH *lh, char *data) 179void *lh_insert(LHASH *lh, void *data)
183 { 180 {
184 unsigned long hash; 181 unsigned long hash;
185 LHASH_NODE *nn,**rn; 182 LHASH_NODE *nn,**rn;
186 char *ret; 183 void *ret;
187 184
188 lh->error=0; 185 lh->error=0;
189 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) 186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
@@ -217,11 +214,11 @@ char *lh_insert(LHASH *lh, char *data)
217 return(ret); 214 return(ret);
218 } 215 }
219 216
220char *lh_delete(LHASH *lh, char *data) 217void *lh_delete(LHASH *lh, void *data)
221 { 218 {
222 unsigned long hash; 219 unsigned long hash;
223 LHASH_NODE *nn,**rn; 220 LHASH_NODE *nn,**rn;
224 char *ret; 221 void *ret;
225 222
226 lh->error=0; 223 lh->error=0;
227 rn=getrn(lh,data,&hash); 224 rn=getrn(lh,data,&hash);
@@ -236,7 +233,7 @@ char *lh_delete(LHASH *lh, char *data)
236 nn= *rn; 233 nn= *rn;
237 *rn=nn->next; 234 *rn=nn->next;
238 ret=nn->data; 235 ret=nn->data;
239 Free((char *)nn); 236 Free(nn);
240 lh->num_delete++; 237 lh->num_delete++;
241 } 238 }
242 239
@@ -248,11 +245,11 @@ char *lh_delete(LHASH *lh, char *data)
248 return(ret); 245 return(ret);
249 } 246 }
250 247
251char *lh_retrieve(LHASH *lh, char *data) 248void *lh_retrieve(LHASH *lh, void *data)
252 { 249 {
253 unsigned long hash; 250 unsigned long hash;
254 LHASH_NODE **rn; 251 LHASH_NODE **rn;
255 char *ret; 252 void *ret;
256 253
257 lh->error=0; 254 lh->error=0;
258 rn=getrn(lh,data,&hash); 255 rn=getrn(lh,data,&hash);
@@ -275,7 +272,7 @@ void lh_doall(LHASH *lh, void (*func)())
275 lh_doall_arg(lh,func,NULL); 272 lh_doall_arg(lh,func,NULL);
276 } 273 }
277 274
278void lh_doall_arg(LHASH *lh, void (*func)(), char *arg) 275void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
279 { 276 {
280 int i; 277 int i;
281 LHASH_NODE *a,*n; 278 LHASH_NODE *a,*n;
@@ -332,7 +329,7 @@ static void expand(LHASH *lh)
332 if ((lh->p) >= lh->pmax) 329 if ((lh->p) >= lh->pmax)
333 { 330 {
334 j=(int)lh->num_alloc_nodes*2; 331 j=(int)lh->num_alloc_nodes*2;
335 n=(LHASH_NODE **)Realloc((char *)lh->b, 332 n=(LHASH_NODE **)Realloc(lh->b,
336 (unsigned int)sizeof(LHASH_NODE *)*j); 333 (unsigned int)sizeof(LHASH_NODE *)*j);
337 if (n == NULL) 334 if (n == NULL)
338 { 335 {
@@ -360,7 +357,7 @@ static void contract(LHASH *lh)
360 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ 357 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
361 if (lh->p == 0) 358 if (lh->p == 0)
362 { 359 {
363 n=(LHASH_NODE **)Realloc((char *)lh->b, 360 n=(LHASH_NODE **)Realloc(lh->b,
364 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); 361 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
365 if (n == NULL) 362 if (n == NULL)
366 { 363 {
@@ -391,7 +388,7 @@ static void contract(LHASH *lh)
391 } 388 }
392 } 389 }
393 390
394static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash) 391static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
395 { 392 {
396 LHASH_NODE **ret,*n1; 393 LHASH_NODE **ret,*n1;
397 unsigned long hash,nn; 394 unsigned long hash,nn;
@@ -426,8 +423,7 @@ static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
426 } 423 }
427 424
428/* 425/*
429static unsigned long lh_strhash(str) 426unsigned long lh_strhash(char *str)
430char *str;
431 { 427 {
432 int i,l; 428 int i,l;
433 unsigned long ret=0; 429 unsigned long ret=0;