The
gcry_err_code_t
type is an alias for thelibgpg-error
typegpg_err_code_t
. The error code indicates the type of an error, or the reason why an operation failed.A list of important error codes can be found in the next section.
The
gcry_err_source_t
type is an alias for thelibgpg-error
typegpg_err_source_t
. The error source has not a precisely defined meaning. Sometimes it is the place where the error happened, sometimes it is the place where an error was encoded into an error value. Usually the error source will give an indication to where to look for the problem. This is not always true, but it is attempted to achieve this goal.A list of important error sources can be found in the next section.
The
gcry_error_t
type is an alias for thelibgpg-error
typegpg_error_t
. An error value like this has always two components, an error code and an error source. Both together form the error value.Thus, the error value can not be directly compared against an error code, but the accessor functions described below must be used. However, it is guaranteed that only 0 is used to indicate success (
GPG_ERR_NO_ERROR
), and that in this case all other parts of the error value are set to 0, too.Note that in Libgcrypt, the error source is used purely for diagnostic purposes. Only the error code should be checked to test for a certain outcome of a function. The manual only documents the error code part of an error value. The error source is left unspecified and might be anything.
The static inline function
gcry_err_code
returns thegcry_err_code_t
component of the error value err. This function must be used to extract the error code from an error value in order to compare it with theGPG_ERR_*
error code macros.
The static inline function
gcry_err_source
returns thegcry_err_source_t
component of the error value err. This function must be used to extract the error source from an error value in order to compare it with theGPG_ERR_SOURCE_*
error source macros.
The static inline function
gcry_err_make
returns the error value consisting of the error source source and the error code code.This function can be used in callback functions to construct an error value to return it to the library.
The static inline function
gcry_error
returns the error value consisting of the default error source and the error code code.For GCRY applications, the default error source is
GPG_ERR_SOURCE_USER_1
. You can defineGCRY_ERR_SOURCE_DEFAULT
before including gcrypt.h to change this default.This function can be used in callback functions to construct an error value to return it to the library.
The libgpg-error
library provides error codes for all system
error numbers it knows about. If err is an unknown error
number, the error code GPG_ERR_UNKNOWN_ERRNO
is used. The
following functions can be used to construct error values from system
errno numbers.
The function
gcry_err_make_from_errno
is likegcry_err_make
, but it takes a system error likeerrno
instead of agcry_err_code_t
error code.
The function
gcry_error_from_errno
is likegcry_error
, but it takes a system error likeerrno
instead of agcry_err_code_t
error code.
Sometimes you might want to map system error numbers to error codes directly, or map an error code representing a system error back to the system error number. The following functions can be used to do that.