1err(3) OpenSSL err(3)
2
3
4
6 err - error codes
7
9 #include <openssl/err.h>
10
11 unsigned long ERR_get_error(void);
12 unsigned long ERR_peek_error(void);
13 unsigned long ERR_get_error_line(const char **file, int *line);
14 unsigned long ERR_peek_error_line(const char **file, int *line);
15 unsigned long ERR_get_error_line_data(const char **file, int *line,
16 const char **data, int *flags);
17 unsigned long ERR_peek_error_line_data(const char **file, int *line,
18 const char **data, int *flags);
19
20 int ERR_GET_LIB(unsigned long e);
21 int ERR_GET_FUNC(unsigned long e);
22 int ERR_GET_REASON(unsigned long e);
23
24 void ERR_clear_error(void);
25
26 char *ERR_error_string(unsigned long e, char *buf);
27 const char *ERR_lib_error_string(unsigned long e);
28 const char *ERR_func_error_string(unsigned long e);
29 const char *ERR_reason_error_string(unsigned long e);
30
31 void ERR_print_errors(BIO *bp);
32 void ERR_print_errors_fp(FILE *fp);
33
34 void ERR_load_crypto_strings(void);
35 void ERR_free_strings(void);
36
37 void ERR_remove_state(unsigned long pid);
38
39 void ERR_put_error(int lib, int func, int reason, const char *file,
40 int line);
41 void ERR_add_error_data(int num, ...);
42
43 void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
44 unsigned long ERR_PACK(int lib, int func, int reason);
45 int ERR_get_next_error_library(void);
46
48 When a call to the OpenSSL library fails, this is usually signalled by
49 the return value, and an error code is stored in an error queue associ‐
50 ated with the current thread. The err library provides functions to
51 obtain these error codes and textual error messages.
52
53 The ERR_get_error(3) manpage describes how to access error codes.
54
55 Error codes contain information about where the error occurred, and
56 what went wrong. ERR_GET_LIB(3) describes how to extract this informa‐
57 tion. A method to obtain human-readable error messages is described in
58 ERR_error_string(3).
59
60 ERR_clear_error(3) can be used to clear the error queue.
61
62 Note that ERR_remove_state(3) should be used to avoid memory leaks when
63 threads are terminated.
64
66 See ERR_put_error(3) if you want to record error codes in the OpenSSL
67 error system from within your application.
68
69 The remainder of this section is of interest only if you want to add
70 new error codes to OpenSSL or add error codes from external libraries.
71
72 Reporting errors
73
74 Each sub-library has a specific macro XXXerr() that is used to report
75 errors. Its first argument is a function code XXX_F_..., the second
76 argument is a reason code XXX_R_.... Function codes are derived from
77 the function names; reason codes consist of textual error descriptions.
78 For example, the function ssl23_read() reports a "handshake failure" as
79 follows:
80
81 SSLerr(SSL_F_SSL23_READ, SSL_R_SSL_HANDSHAKE_FAILURE);
82
83 Function and reason codes should consist of upper case characters, num‐
84 bers and underscores only. The error file generation script translates
85 function codes into function names by looking in the header files for
86 an appropriate function name, if none is found it just uses the capi‐
87 talized form such as "SSL23_READ" in the above example.
88
89 The trailing section of a reason code (after the "_R_") is translated
90 into lower case and underscores changed to spaces.
91
92 When you are using new function or reason codes, run make errors. The
93 necessary #defines will then automatically be added to the
94 sub-library's header file.
95
96 Although a library will normally report errors using its own specific
97 XXXerr macro, another library's macro can be used. This is normally
98 only done when a library wants to include ASN1 code which must use the
99 ASN1err() macro.
100
101 Adding new libraries
102
103 When adding a new sub-library to OpenSSL, assign it a library number
104 ERR_LIB_XXX, define a macro XXXerr() (both in err.h), add its name to
105 ERR_str_libraries[] (in crypto/err/err.c), and add
106 "ERR_load_XXX_strings()" to the ERR_load_crypto_strings() function (in
107 crypto/err/err_all.c). Finally, add an entry
108
109 L XXX xxx.h xxx_err.c
110
111 to crypto/err/openssl.ec, and add xxx_err.c to the Makefile. Running
112 make errors will then generate a file xxx_err.c, and add all error
113 codes used in the library to xxx.h.
114
115 Additionally the library include file must have a certain form. Typi‐
116 cally it will initially look like this:
117
118 #ifndef HEADER_XXX_H
119 #define HEADER_XXX_H
120
121 #ifdef __cplusplus
122 extern "C" {
123 #endif
124
125 /* Include files */
126
127 #include <openssl/bio.h>
128 #include <openssl/x509.h>
129
130 /* Macros, structures and function prototypes */
131
132 /* BEGIN ERROR CODES */
133
134 The BEGIN ERROR CODES sequence is used by the error code generation
135 script as the point to place new error codes, any text after this point
136 will be overwritten when make errors is run. The closing #endif etc
137 will be automatically added by the script.
138
139 The generated C error code file xxx_err.c will load the header files
140 stdio.h, openssl/err.h and openssl/xxx.h so the header file must load
141 any additional header files containing any definitions it uses.
142
144 It is also possible to use OpenSSL's error code scheme in external
145 libraries. The library needs to load its own codes and call the OpenSSL
146 error code insertion script mkerr.pl explicitly to add codes to the
147 header file and generate the C error code file. This will normally be
148 done if the external library needs to generate new ASN1 structures but
149 it can also be used to add more general purpose error code handling.
150
151 TBA more details
152
154 The error queues are stored in a hash table with one ERR_STATE entry
155 for each pid. ERR_get_state() returns the current thread's ERR_STATE.
156 An ERR_STATE can hold up to ERR_NUM_ERRORS error codes. When more error
157 codes are added, the old ones are overwritten, on the assumption that
158 the most recent errors are most important.
159
160 Error strings are also stored in hash table. The hash tables can be
161 obtained by calling ERR_get_err_state_table(void) and
162 ERR_get_string_table(void) respectively.
163
165 CRYPTO_set_id_callback(3), CRYPTO_set_locking_callback(3),
166 ERR_get_error(3), ERR_GET_LIB(3), ERR_clear_error(3),
167 ERR_error_string(3), ERR_print_errors(3), ERR_load_crypto_strings(3),
168 ERR_remove_state(3), ERR_put_error(3), ERR_load_strings(3),
169 SSL_get_error(3)
170
171
172
1730.9.8b 2002-07-10 err(3)