2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* crypto/err/err.c */
20 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
21 * All rights reserved.
23 * This package is an SSL implementation written
24 * by Eric Young (eay@cryptsoft.com).
25 * The implementation was written so as to conform with Netscapes SSL.
27 * This library is free for commercial and non-commercial use as long as
28 * the following conditions are aheared to. The following conditions
29 * apply to all code found in this distribution, be it the RC4, RSA,
30 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
31 * included with this distribution is covered by the same copyright terms
32 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
34 * Copyright remains Eric Young's, and as such any Copyright notices in
35 * the code are not to be removed.
36 * If this package is used in a product, Eric Young should be given attribution
37 * as the author of the parts of the library used.
38 * This can be in the form of a textual message at program startup or
39 * in documentation (online or textual) provided with the package.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * "This product includes cryptographic software written by
52 * Eric Young (eay@cryptsoft.com)"
53 * The word 'cryptographic' can be left out if the rouines from the library
54 * being used are not cryptographic related :-).
55 * 4. If you include any Windows specific code (or a derivative thereof) from
56 * the apps directory (application code) you must include an acknowledgement:
57 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
59 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * The licence and distribution terms for any publically available version or
72 * derivative of this code cannot be changed. i.e. this code cannot simply be
73 * copied and put under another distribution licence
74 * [including the GNU Public Licence.]
76 /* ====================================================================
77 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
79 * Redistribution and use in source and binary forms, with or without
80 * modification, are permitted provided that the following conditions
83 * 1. Redistributions of source code must retain the above copyright
84 * notice, this list of conditions and the following disclaimer.
86 * 2. Redistributions in binary form must reproduce the above copyright
87 * notice, this list of conditions and the following disclaimer in
88 * the documentation and/or other materials provided with the
91 * 3. All advertising materials mentioning features or use of this
92 * software must display the following acknowledgment:
93 * "This product includes software developed by the OpenSSL Project
94 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
96 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
97 * endorse or promote products derived from this software without
98 * prior written permission. For written permission, please contact
99 * openssl-core@openssl.org.
101 * 5. Products derived from this software may not be called "OpenSSL"
102 * nor may "OpenSSL" appear in their names without prior written
103 * permission of the OpenSSL Project.
105 * 6. Redistributions of any form whatsoever must retain the following
107 * "This product includes software developed by the OpenSSL Project
108 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
110 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
111 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
113 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
114 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
115 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
116 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
117 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
118 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
119 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
120 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
121 * OF THE POSSIBILITY OF SUCH DAMAGE.
122 * ====================================================================
124 * This product includes cryptographic software written by Eric Young
125 * (eay@cryptsoft.com). This product includes software written by Tim
126 * Hudson (tjh@cryptsoft.com).
133 #include <openssl/opensslconf.h>
134 #include <openssl/lhash.h>
135 #include <openssl/crypto.h>
136 #include "cryptlib.h"
137 #include <openssl/buffer.h>
138 #include <openssl/err.h>
139 #include <openssl/crypto.h>
142 static LHASH
*error_hash
=NULL
;
143 static LHASH
*thread_hash
=NULL
;
145 static unsigned long err_hash(ERR_STRING_DATA
*a
);
146 static int err_cmp(ERR_STRING_DATA
*a
, ERR_STRING_DATA
*b
);
147 static unsigned long pid_hash(ERR_STATE
*pid
);
148 static int pid_cmp(ERR_STATE
*a
,ERR_STATE
*pid
);
149 static unsigned long get_error_values(int inc
,const char **file
,int *line
,
150 const char **data
,int *flags
);
151 static void ERR_STATE_free(ERR_STATE
*s
);
153 static ERR_STRING_DATA ERR_str_libraries
[]=
155 {ERR_PACK(ERR_LIB_NONE
,0,0) ,"unknown library"},
156 {ERR_PACK(ERR_LIB_SYS
,0,0) ,"system library"},
157 {ERR_PACK(ERR_LIB_BN
,0,0) ,"bignum routines"},
158 {ERR_PACK(ERR_LIB_RSA
,0,0) ,"rsa routines"},
159 {ERR_PACK(ERR_LIB_DH
,0,0) ,"Diffie-Hellman routines"},
160 {ERR_PACK(ERR_LIB_EVP
,0,0) ,"digital envelope routines"},
161 {ERR_PACK(ERR_LIB_BUF
,0,0) ,"memory buffer routines"},
162 {ERR_PACK(ERR_LIB_BIO
,0,0) ,"BIO routines"},
163 {ERR_PACK(ERR_LIB_OBJ
,0,0) ,"object identifier routines"},
164 {ERR_PACK(ERR_LIB_PEM
,0,0) ,"PEM routines"},
165 {ERR_PACK(ERR_LIB_ASN1
,0,0) ,"asn1 encoding routines"},
166 {ERR_PACK(ERR_LIB_X509
,0,0) ,"x509 certificate routines"},
167 {ERR_PACK(ERR_LIB_CONF
,0,0) ,"configuration file routines"},
168 {ERR_PACK(ERR_LIB_METH
,0,0) ,"X509 lookup 'method' routines"},
169 {ERR_PACK(ERR_LIB_SSL
,0,0) ,"SSL routines"},
170 {ERR_PACK(ERR_LIB_RSAREF
,0,0) ,"RSAref routines"},
171 {ERR_PACK(ERR_LIB_PROXY
,0,0) ,"Proxy routines"},
172 {ERR_PACK(ERR_LIB_BIO
,0,0) ,"BIO routines"},
173 {ERR_PACK(ERR_LIB_PKCS7
,0,0) ,"PKCS7 routines"},
174 {ERR_PACK(ERR_LIB_X509V3
,0,0) ,"X509 V3 routines"},
175 {ERR_PACK(ERR_LIB_PKCS12
,0,0) ,"PKCS12 routines"},
176 {ERR_PACK(ERR_LIB_RAND
,0,0) ,"random number generator"},
180 static ERR_STRING_DATA ERR_str_functs
[]=
182 {ERR_PACK(0,SYS_F_FOPEN
,0), "fopen"},
183 {ERR_PACK(0,SYS_F_CONNECT
,0), "connect"},
184 {ERR_PACK(0,SYS_F_GETSERVBYNAME
,0), "getservbyname"},
185 {ERR_PACK(0,SYS_F_SOCKET
,0), "socket"},
186 {ERR_PACK(0,SYS_F_IOCTLSOCKET
,0), "ioctlsocket"},
187 {ERR_PACK(0,SYS_F_BIND
,0), "bind"},
188 {ERR_PACK(0,SYS_F_LISTEN
,0), "listen"},
189 {ERR_PACK(0,SYS_F_ACCEPT
,0), "accept"},
191 {ERR_PACK(0,SYS_F_WSASTARTUP
,0), "WSAstartup"},
193 {ERR_PACK(0,SYS_F_OPENDIR
,0), "opendir"},
197 static ERR_STRING_DATA ERR_str_reasons
[]=
199 {ERR_R_FATAL
,"fatal"},
200 {ERR_R_SYS_LIB
,"system lib"},
201 {ERR_R_BN_LIB
,"BN lib"},
202 {ERR_R_RSA_LIB
,"RSA lib"},
203 {ERR_R_DH_LIB
,"DH lib"},
204 {ERR_R_EVP_LIB
,"EVP lib"},
205 {ERR_R_BUF_LIB
,"BUF lib"},
206 {ERR_R_BIO_LIB
,"BIO lib"},
207 {ERR_R_OBJ_LIB
,"OBJ lib"},
208 {ERR_R_PEM_LIB
,"PEM lib"},
209 {ERR_R_X509_LIB
,"X509 lib"},
210 {ERR_R_METH_LIB
,"METH lib"},
211 {ERR_R_ASN1_LIB
,"ASN1 lib"},
212 {ERR_R_CONF_LIB
,"CONF lib"},
213 {ERR_R_SSL_LIB
,"SSL lib"},
214 {ERR_R_PROXY_LIB
,"PROXY lib"},
215 {ERR_R_BIO_LIB
,"BIO lib"},
216 {ERR_R_PKCS7_LIB
,"PKCS7 lib"},
217 {ERR_R_PKCS12_LIB
,"PKCS12 lib"},
218 {ERR_R_MALLOC_FAILURE
,"Malloc failure"},
219 {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
,"called a function you should not call"},
220 {ERR_R_PASSED_NULL_PARAMETER
,"passed a null parameter"},
221 {ERR_R_NESTED_ASN1_ERROR
,"nested asn1 error"},
222 {ERR_R_BAD_ASN1_OBJECT_HEADER
,"bad asn1 object header"},
223 {ERR_R_BAD_GET_ASN1_OBJECT_CALL
,"bad get asn1 object call"},
224 {ERR_R_EXPECTING_AN_ASN1_SEQUENCE
,"expecting an asn1 sequence"},
225 {ERR_R_ASN1_LENGTH_MISMATCH
,"asn1 length mismatch"},
226 {ERR_R_MISSING_ASN1_EOS
,"missing asn1 eos"},
232 #define NUM_SYS_STR_REASONS 127
233 #define LEN_SYS_STR_REASON 32
235 static ERR_STRING_DATA SYS_str_reasons
[NUM_SYS_STR_REASONS
+ 1];
236 /* SYS_str_reasons is filled with copies of strerror() results at
238 * 'errno' values up to 127 should cover all usual errors,
239 * others will be displayed numerically by ERR_error_string.
240 * It is crucial that we have something for each reason code
241 * that occurs in ERR_str_reasons, or bogus reason strings
242 * will be returned for SYSerr(), which always gets an errno
243 * value and never one of those 'standard' reason codes. */
245 static void build_SYS_str_reasons()
247 /* Malloc cannot be used here, use static storage instead */
248 static char strerror_tab
[NUM_SYS_STR_REASONS
][LEN_SYS_STR_REASON
];
251 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH
);
253 for (i
= 1; i
<= NUM_SYS_STR_REASONS
; i
++)
255 ERR_STRING_DATA
*str
= &SYS_str_reasons
[i
- 1];
257 str
->error
= (unsigned long)i
;
258 if (str
->string
== NULL
)
260 char (*dest
)[LEN_SYS_STR_REASON
] = &(strerror_tab
[i
- 1]);
261 char *src
= strerror(i
);
264 strncpy(*dest
, src
, sizeof *dest
);
265 (*dest
)[sizeof *dest
- 1] = '\0';
269 if (str
->string
== NULL
)
270 str
->string
= "unknown";
273 /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
274 * as required by ERR_load_strings. */
276 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH
);
280 #define err_clear_data(p,i) \
281 if (((p)->err_data[i] != NULL) && \
282 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
284 Free((p)->err_data[i]); \
285 (p)->err_data[i]=NULL; \
287 (p)->err_data_flags[i]=0;
289 static void ERR_STATE_free(ERR_STATE
*s
)
296 for (i
=0; i
<ERR_NUM_ERRORS
; i
++)
303 void ERR_load_ERR_strings(void)
309 CRYPTO_w_lock(CRYPTO_LOCK_ERR
);
312 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
315 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
318 ERR_load_strings(0,ERR_str_libraries
);
319 ERR_load_strings(0,ERR_str_reasons
);
320 ERR_load_strings(ERR_LIB_SYS
,ERR_str_functs
);
321 build_SYS_str_reasons();
322 ERR_load_strings(ERR_LIB_SYS
,SYS_str_reasons
);
328 void ERR_load_strings(int lib
, ERR_STRING_DATA
*str
)
330 if (error_hash
== NULL
)
332 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH
);
333 error_hash
=lh_new(err_hash
,err_cmp
);
334 if (error_hash
== NULL
)
336 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH
);
339 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH
);
341 ERR_load_ERR_strings();
344 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH
);
347 str
->error
|=ERR_PACK(lib
,0,0);
348 lh_insert(error_hash
,str
);
351 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH
);
354 void ERR_free_strings(void)
356 CRYPTO_w_lock(CRYPTO_LOCK_ERR
);
358 if (error_hash
!= NULL
)
364 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
367 /********************************************************/
369 void ERR_put_error(int lib
, int func
, int reason
, const char *file
,
375 /* In the BS2000-OSD POSIX subsystem, the compiler generates
376 * path names in the form "*POSIX(/etc/passwd)".
377 * This dirty hack strips them to something sensible.
378 * @@@ We shouldn't modify a const string, though.
380 if (strncmp(file
,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
383 /* Skip the "*POSIX(" prefix */
384 file
+= sizeof("*POSIX(")-1;
385 end
= &file
[strlen(file
)-1];
388 /* Optional: use the basename of the path only. */
389 if ((end
= strrchr(file
, '/')) != NULL
)
395 es
->top
=(es
->top
+1)%ERR_NUM_ERRORS
;
396 if (es
->top
== es
->bottom
)
397 es
->bottom
=(es
->bottom
+1)%ERR_NUM_ERRORS
;
398 es
->err_buffer
[es
->top
]=ERR_PACK(lib
,func
,reason
);
399 es
->err_file
[es
->top
]=file
;
400 es
->err_line
[es
->top
]=line
;
401 err_clear_data(es
,es
->top
);
404 void ERR_clear_error(void)
411 /* hmm... is this needed */
412 for (i
=0; i
<ERR_NUM_ERRORS
; i
++)
415 es
->err_file
[i
]=NULL
;
417 err_clear_data(es
,i
);
420 es
->top
=es
->bottom
=0;
424 unsigned long ERR_get_error(void)
425 { return(get_error_values(1,NULL
,NULL
,NULL
,NULL
)); }
427 unsigned long ERR_get_error_line(const char **file
,
429 { return(get_error_values(1,file
,line
,NULL
,NULL
)); }
431 unsigned long ERR_get_error_line_data(const char **file
, int *line
,
432 const char **data
, int *flags
)
433 { return(get_error_values(1,file
,line
,
436 unsigned long ERR_peek_error(void)
437 { return(get_error_values(0,NULL
,NULL
,NULL
,NULL
)); }
439 unsigned long ERR_peek_error_line(const char **file
,
441 { return(get_error_values(0,file
,line
,NULL
,NULL
)); }
443 unsigned long ERR_peek_error_line_data(const char **file
, int *line
,
444 const char **data
, int *flags
)
445 { return(get_error_values(0,file
,line
,
448 static unsigned long get_error_values(int inc
, const char **file
, int *line
,
449 const char **data
, int *flags
)
457 if (es
->bottom
== es
->top
) return(0);
458 i
=(es
->bottom
+1)%ERR_NUM_ERRORS
;
460 ret
=es
->err_buffer
[i
];
467 if ((file
!= NULL
) && (line
!= NULL
))
469 if (es
->err_file
[i
] == NULL
)
472 if (line
!= NULL
) *line
=0;
476 *file
=es
->err_file
[i
];
477 if (line
!= NULL
) *line
=es
->err_line
[i
];
483 if (es
->err_data
[i
] == NULL
)
486 if (flags
!= NULL
) *flags
=0;
490 *data
=es
->err_data
[i
];
491 if (flags
!= NULL
) *flags
=es
->err_data_flags
[i
];
497 /* BAD for multi-threaded, uses a local buffer if ret == NULL */
498 char *ERR_error_string(unsigned long e
, char *ret
)
502 strcpy(ret
, "No Error String Info.");
504 return "No Error String info.";
506 static char buf
[256];
507 const char *ls
,*fs
,*rs
;
515 ls
=ERR_lib_error_string(e
);
516 fs
=ERR_func_error_string(e
);
517 rs
=ERR_reason_error_string(e
);
519 if (ret
== NULL
) ret
=buf
;
521 sprintf(&(ret
[0]),"error:%08lX:",e
);
524 sprintf(&(ret
[i
]),":lib(%lu) ",l
);
525 else sprintf(&(ret
[i
]),"%s",ls
);
528 sprintf(&(ret
[i
]),":func(%lu) ",f
);
529 else sprintf(&(ret
[i
]),":%s",fs
);
532 sprintf(&(ret
[i
]),":reason(%lu)",r
);
533 else sprintf(&(ret
[i
]),":%s",rs
);
539 LHASH
*ERR_get_string_table(void)
544 LHASH
*ERR_get_err_state_table(void)
549 const char *ERR_lib_error_string(unsigned long e
)
551 ERR_STRING_DATA d
,*p
=NULL
;
556 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH
);
558 if (error_hash
!= NULL
)
560 d
.error
=ERR_PACK(l
,0,0);
561 p
=(ERR_STRING_DATA
*)lh_retrieve(error_hash
,&d
);
564 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH
);
566 return((p
== NULL
)?NULL
:p
->string
);
569 const char *ERR_func_error_string(unsigned long e
)
571 ERR_STRING_DATA d
,*p
=NULL
;
577 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH
);
579 if (error_hash
!= NULL
)
581 d
.error
=ERR_PACK(l
,f
,0);
582 p
=(ERR_STRING_DATA
*)lh_retrieve(error_hash
,&d
);
585 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH
);
587 return((p
== NULL
)?NULL
:p
->string
);
590 const char *ERR_reason_error_string(unsigned long e
)
592 ERR_STRING_DATA d
,*p
=NULL
;
598 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH
);
600 if (error_hash
!= NULL
)
602 d
.error
=ERR_PACK(l
,0,r
);
603 p
=(ERR_STRING_DATA
*)lh_retrieve(error_hash
,&d
);
606 d
.error
=ERR_PACK(0,0,r
);
607 p
=(ERR_STRING_DATA
*)lh_retrieve(error_hash
,&d
);
611 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH
);
613 return((p
== NULL
)?NULL
:p
->string
);
616 static unsigned long err_hash(ERR_STRING_DATA
*a
)
621 ret
=l
^ERR_GET_LIB(l
)^ERR_GET_FUNC(l
);
622 return(ret
^ret%19
*13);
625 static int err_cmp(ERR_STRING_DATA
*a
, ERR_STRING_DATA
*b
)
627 return((int)(a
->error
-b
->error
));
630 static unsigned long pid_hash(ERR_STATE
*a
)
635 static int pid_cmp(ERR_STATE
*a
, ERR_STATE
*b
)
637 return((int)((long)a
->pid
- (long)b
->pid
));
640 void ERR_remove_state(unsigned long pid
)
644 if (thread_hash
== NULL
)
647 pid
=(unsigned long)CRYPTO_thread_id();
649 CRYPTO_w_lock(CRYPTO_LOCK_ERR
);
650 p
=(ERR_STATE
*)lh_delete(thread_hash
,&tmp
);
651 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
653 if (p
!= NULL
) ERR_STATE_free(p
);
656 static ERR_STATE
*fallback
= NULL
;
657 static ERR_STATE
*getFallback()
659 if(fallback
== NULL
) {
660 fallback
= (ERR_STATE
*)Malloc(sizeof(ERR_STATE
));
665 ERR_STATE
*ERR_get_state(void)
667 ERR_STATE
*ret
=NULL
,tmp
,*tmpp
;
671 pid
=(unsigned long)CRYPTO_thread_id();
673 CRYPTO_r_lock(CRYPTO_LOCK_ERR
);
674 if (thread_hash
== NULL
)
676 CRYPTO_r_unlock(CRYPTO_LOCK_ERR
);
677 CRYPTO_w_lock(CRYPTO_LOCK_ERR
);
678 if (thread_hash
== NULL
)
681 thread_hash
=lh_new(pid_hash
,pid_cmp
);
683 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
684 if (thread_hash
== NULL
) return(getFallback());
687 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
692 ret
=(ERR_STATE
*)lh_retrieve(thread_hash
,&tmp
);
693 CRYPTO_r_unlock(CRYPTO_LOCK_ERR
);
696 /* ret == the error state, if NULL, make a new one */
699 ret
=(ERR_STATE
*)Malloc(sizeof(ERR_STATE
));
700 if (ret
== NULL
) return(getFallback());
704 for (i
=0; i
<ERR_NUM_ERRORS
; i
++)
706 ret
->err_data
[i
]=NULL
;
707 ret
->err_data_flags
[i
]=0;
709 CRYPTO_w_lock(CRYPTO_LOCK_ERR
);
710 tmpp
=(ERR_STATE
*)lh_insert(thread_hash
,ret
);
711 CRYPTO_w_unlock(CRYPTO_LOCK_ERR
);
712 if (tmpp
!= NULL
) /* old entry - should not happen */
714 ERR_STATE_free(tmpp
);
720 int ERR_get_next_error_library(void)
722 static int value
=ERR_LIB_USER
;
727 void ERR_set_error_data(char *data
, int flags
)
738 es
->err_data
[i
]=data
;
739 es
->err_data_flags
[es
->top
]=flags
;
742 void ERR_add_error_data(int num
, ...)
750 if (str
== NULL
) return;
755 for (i
=0; i
<num
; i
++)
757 a
=va_arg(args
, char*);
758 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
777 ERR_set_error_data(str
,ERR_TXT_MALLOCED
|ERR_TXT_STRING
);