Newer
Older
#ifndef OPENSSL_NO_DEPRECATED
void ERR_remove_state(unsigned long pid)
{
ERR_remove_thread_state(NULL);
}
#endif
{
static ERR_STATE fallback;
CRYPTO_THREADID tid;
ERR_STATE *ret,tmp,*tmpp=NULL;
err_fns_check();
CRYPTO_THREADID_set(&tid);
CRYPTO_THREADID_cpy(&tmp.tid, &tid);
ret=ERRFN(thread_get_item)(&tmp);
/* ret == the error state, if NULL, make a new one */
if (ret == NULL)
{
Richard Levitte
committed
ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
if (ret == NULL) return(&fallback);
CRYPTO_THREADID_cpy(&ret->tid, &tid);
ret->top=0;
ret->bottom=0;
for (i=0; i<ERR_NUM_ERRORS; i++)
{
ret->err_data[i]=NULL;
ret->err_data_flags[i]=0;
}
tmpp = ERRFN(thread_set_item)(ret);
/* To check if insertion failed, do a get. */
if (ERRFN(thread_get_item)(ret) != ret)
{
ERR_STATE_free(ret); /* could not insert it */
return(&fallback);
}
/* If a race occured in this function and we came second, tmpp
* is the first one that we just replaced. */
ERR_STATE_free(tmpp);
err_fns_check();
return ERRFN(get_next_lib)();
void ERR_set_error_data(char *data, int flags)
{
ERR_STATE *es;
int i;
es=ERR_get_state();
i=es->top;
if (i == 0)
i=ERR_NUM_ERRORS-1;
es->err_data[i]=data;
int i,n,s;
char *str,*p,*a;
Richard Levitte
committed
str=OPENSSL_malloc(s+1);
if (str == NULL) return;
str[0]='\0';
n=0;
for (i=0; i<num; i++)
{
/* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
if (a != NULL)
n+=strlen(a);
if (n > s)
Richard Levitte
committed
p=OPENSSL_realloc(str,s+1);
if (p == NULL)
{
Richard Levitte
committed
OPENSSL_free(str);
Richard Levitte
committed
goto err;
}
else
str=p;
}
}
ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
Richard Levitte
committed
err:
Richard Levitte
committed
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
int ERR_set_mark(void)
{
ERR_STATE *es;
es=ERR_get_state();
if (es->bottom == es->top) return 0;
es->err_flags[es->top]|=ERR_FLAG_MARK;
return 1;
}
int ERR_pop_to_mark(void)
{
ERR_STATE *es;
es=ERR_get_state();
while(es->bottom != es->top
&& (es->err_flags[es->top] & ERR_FLAG_MARK) == 0)
{
err_clear(es,es->top);
es->top-=1;
if (es->top == -1) es->top=ERR_NUM_ERRORS-1;
Richard Levitte
committed
}
if (es->bottom == es->top) return 0;
es->err_flags[es->top]&=~ERR_FLAG_MARK;
return 1;
}