*/
#include <stdio.h>
#include "cryptlib.h"
-#include "stack.h"
+#include <openssl/stack.h>
#undef MIN_NODES
#define MIN_NODES 4
-char *STACK_version="Stack part of OpenSSL 0.9.2 31-Dec-1998";
+const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
-#ifndef NOPROTO
#define FP_ICC (int (*)(const void *,const void *))
-#else
-#define FP_ICC
-#endif
-
#include <errno.h>
-void sk_set_cmp_func(sk,c)
-STACK *sk;
-int (*c)();
+int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void)
{
+ int (*old)()=sk->comp;
+
if (sk->comp != c)
sk->sorted=0;
sk->comp=c;
+
+ return old;
}
-STACK *sk_dup(sk)
-STACK *sk;
+STACK *sk_dup(STACK *sk)
{
STACK *ret;
char **s;
return(NULL);
}
-STACK *sk_new(c)
-int (*c)();
+STACK *sk_new(int (*c)())
{
STACK *ret;
int i;
return(NULL);
}
-int sk_insert(st,data,loc)
-STACK *st;
-char *data;
-int loc;
+int sk_insert(STACK *st, char *data, int loc)
{
char **s;
+ if(st == NULL) return 0;
if (st->num_alloc <= st->num+1)
{
s=(char **)Realloc((char *)st->data,
return(st->num);
}
-char *sk_delete_ptr(st,p)
-STACK *st;
-char *p;
+char *sk_delete_ptr(STACK *st, char *p)
{
int i;
return(NULL);
}
-char *sk_delete(st,loc)
-STACK *st;
-int loc;
+char *sk_delete(STACK *st, int loc)
{
char *ret;
int i,j;
- if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL);
+ if ((st == NULL) || (st->num == 0) || (loc < 0)
+ || (loc >= st->num)) return(NULL);
ret=st->data[loc];
if (loc != st->num-1)
return(ret);
}
-int sk_find(st,data)
-STACK *st;
-char *data;
+int sk_find(STACK *st, char *data)
{
char **r;
int i;
int (*comp_func)();
+ if(st == NULL) return -1;
if (st->comp == NULL)
{
return(i);
return(-1);
}
- comp_func=(int (*)())st->comp;
- if (!st->sorted)
- {
- qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func);
- st->sorted=1;
- }
+ sk_sort(st);
if (data == NULL) return(-1);
+ comp_func=(int (*)())st->comp;
r=(char **)bsearch(&data,(char *)st->data,
st->num,sizeof(char *),FP_ICC comp_func);
if (r == NULL) return(-1);
return(i);
}
-int sk_push(st,data)
-STACK *st;
-char *data;
+int sk_push(STACK *st, char *data)
{
return(sk_insert(st,data,st->num));
}
-int sk_unshift(st,data)
-STACK *st;
-char *data;
+int sk_unshift(STACK *st, char *data)
{
return(sk_insert(st,data,0));
}
-char *sk_shift(st)
-STACK *st;
+char *sk_shift(STACK *st)
{
if (st == NULL) return(NULL);
if (st->num <= 0) return(NULL);
return(sk_delete(st,0));
}
-char *sk_pop(st)
-STACK *st;
+char *sk_pop(STACK *st)
{
if (st == NULL) return(NULL);
if (st->num <= 0) return(NULL);
return(sk_delete(st,st->num-1));
}
-void sk_zero(st)
-STACK *st;
+void sk_zero(STACK *st)
{
if (st == NULL) return;
if (st->num <= 0) return;
st->num=0;
}
-void sk_pop_free(st,func)
-STACK *st;
-void (*func)();
+void sk_pop_free(STACK *st, void (*func)())
{
int i;
sk_free(st);
}
-void sk_free(st)
-STACK *st;
+void sk_free(STACK *st)
{
if (st == NULL) return;
if (st->data != NULL) Free((char *)st->data);
Free((char *)st);
}
+int sk_num(STACK *st)
+{
+ if(st == NULL) return -1;
+ return st->num;
+}
+
+char *sk_value(STACK *st, int i)
+{
+ if(st == NULL) return NULL;
+ return st->data[i];
+}
+
+char *sk_set(STACK *st, int i, char *value)
+{
+ if(st == NULL) return NULL;
+ return (st->data[i] = value);
+}
+
+void sk_sort(STACK *st)
+ {
+ if (!st->sorted)
+ {
+ int (*comp_func)();
+
+ comp_func=(int (*)())st->comp;
+ qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func);
+ st->sorted=1;
+ }
+ }