Fix strange formatting by indent
[oweals/openssl.git] / crypto / stack / stack.c
index 98a3eeee64afaaa8c3edc71aa8d360a12be26a82..fb2cc95ad4b52a7993c3deff269d1277af82dbe8 100644 (file)
@@ -56,7 +56,8 @@
  * [including the GNU Public Licence.]
  */
 
-/* Code for stacks
+/*-
+ * Code for stacks
  * Author - Eric Young v 1.0
  * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the
  *                     lowest index for the searched item.
 #include <stdio.h>
 #include "cryptlib.h"
 #include <openssl/stack.h>
+#include <openssl/objects.h>
 
 #undef MIN_NODES
 #define MIN_NODES      4
 
-const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
+const char STACK_version[]="Stack" OPENSSL_VERSION_PTEXT;
 
 #include <errno.h>
 
@@ -191,8 +193,7 @@ char *sk_delete(STACK *st, int loc)
        char *ret;
        int i,j;
 
-       if ((st == NULL) || (st->num == 0) || (loc < 0)
-                                        || (loc >= st->num)) return(NULL);
+       if(!st || (loc < 0) || (loc >= st->num)) return NULL;
 
        ret=st->data[loc];
        if (loc != st->num-1)
@@ -233,7 +234,7 @@ static int internal_find(STACK *st, char *data, int ret_val_options)
         * not (type *) pointers, but the *pointers* to (type *) pointers,
         * so we get our extra level of pointer dereferencing that way. */
        comp_func=(int (*)(const void *,const void *))(st->comp);
-       r=(char **)OBJ_bsearch(&data,(char *)st->data,
+       r=(char **)OBJ_bsearch_ex((char *)&data,(char *)st->data,
                st->num,sizeof(char *),comp_func,ret_val_options);
        if (r == NULL) return(-1);
        return((int)(r-st->data));
@@ -306,13 +307,13 @@ int sk_num(const STACK *st)
 
 char *sk_value(const STACK *st, int i)
 {
-       if(st == NULL) return NULL;
+       if(!st || (i < 0) || (i >= st->num)) return NULL;
        return st->data[i];
 }
 
 char *sk_set(STACK *st, int i, char *value)
 {
-       if(st == NULL) return NULL;
+       if(!st || (i < 0) || (i >= st->num)) return NULL;
        return (st->data[i] = value);
 }
 
@@ -332,3 +333,10 @@ void sk_sort(STACK *st)
                st->sorted=1;
                }
        }
+
+int sk_is_sorted(const STACK *st)
+       {
+       if (!st)
+               return 1;
+       return st->sorted;
+       }