Lines Matching refs:st
142 int sk_insert(_STACK *st, void *data, int loc)
146 if(st == NULL) return 0;
147 if (st->num_alloc <= st->num+1)
149 s=OPENSSL_realloc((char *)st->data,
150 (unsigned int)sizeof(char *)*st->num_alloc*2);
153 st->data=s;
154 st->num_alloc*=2;
156 if ((loc >= (int)st->num) || (loc < 0))
157 st->data[st->num]=data;
163 f=st->data;
164 t=&(st->data[1]);
165 for (i=st->num; i>=loc; i--)
169 memmove(&(st->data[loc+1]),
170 &(st->data[loc]),
171 sizeof(char *)*(st->num-loc));
173 st->data[loc]=data;
175 st->num++;
176 st->sorted=0;
177 return(st->num);
180 void *sk_delete_ptr(_STACK *st, void *p)
184 for (i=0; i<st->num; i++)
185 if (st->data[i] == p)
186 return(sk_delete(st,i));
190 void *sk_delete(_STACK *st, int loc)
195 if(!st || (loc < 0) || (loc >= st->num)) return NULL;
197 ret=st->data[loc];
198 if (loc != st->num-1)
200 j=st->num-1;
202 st->data[i]=st->data[i+1];
204 * memcpy( &(st->data[loc]),
205 * &(st->data[loc+1]),
206 * sizeof(char *)*(st->num-loc-1));
209 st->num--;
213 static int internal_find(_STACK *st, void *data, int ret_val_options)
218 if(st == NULL) return -1;
220 if (st->comp == NULL)
222 for (i=0; i<st->num; i++)
223 if (st->data[i] == data)
227 sk_sort(st);
229 r=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp,
232 return (int)((char **)r-st->data);
235 int sk_find(_STACK *st, void *data)
237 return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
239 int sk_find_ex(_STACK *st, void *data)
241 return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH);
244 int sk_push(_STACK *st, void *data)
246 return(sk_insert(st,data,st->num));
249 int sk_unshift(_STACK *st, void *data)
251 return(sk_insert(st,data,0));
254 void *sk_shift(_STACK *st)
256 if (st == NULL) return(NULL);
257 if (st->num <= 0) return(NULL);
258 return(sk_delete(st,0));
261 void *sk_pop(_STACK *st)
263 if (st == NULL) return(NULL);
264 if (st->num <= 0) return(NULL);
265 return(sk_delete(st,st->num-1));
268 void sk_zero(_STACK *st)
270 if (st == NULL) return;
271 if (st->num <= 0) return;
272 memset((char *)st->data,0,sizeof(st->data)*st->num);
273 st->num=0;
276 void sk_pop_free(_STACK *st, void (*func)(void *))
280 if (st == NULL) return;
281 for (i=0; i<st->num; i++)
282 if (st->data[i] != NULL)
283 func(st->data[i]);
284 sk_free(st);
287 void sk_free(_STACK *st)
289 if (st == NULL) return;
290 if (st->data != NULL) OPENSSL_free(st->data);
291 OPENSSL_free(st);
294 int sk_num(const _STACK *st)
296 if(st == NULL) return -1;
297 return st->num;
300 void *sk_value(const _STACK *st, int i)
302 if(!st || (i < 0) || (i >= st->num)) return NULL;
303 return st->data[i];
306 void *sk_set(_STACK *st, int i, void *value)
308 if(!st || (i < 0) || (i >= st->num)) return NULL;
309 return (st->data[i] = value);
312 void sk_sort(_STACK *st)
314 if (st && !st->sorted)
318 /* same comment as in sk_find ... previously st->comp was declared
323 comp_func=(int (*)(const void *,const void *))(st->comp);
324 qsort(st->data,st->num,sizeof(char *), comp_func);
325 st->sorted=1;
329 int sk_is_sorted(const _STACK *st)
331 if (!st)
333 return st->sorted;