diff options
Diffstat (limited to 'src/code-from-errno.c')
-rw-r--r-- | src/code-from-errno.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/code-from-errno.c b/src/code-from-errno.c index d431ef1..96fcf20 100644 --- a/src/code-from-errno.c +++ b/src/code-from-errno.c @@ -22,6 +22,8 @@ #include <config.h> #endif +#include <errno.h> + #include <gpg-error.h> #include "code-from-errno.h" @@ -32,11 +34,34 @@ gpg_err_code_t gpg_err_code_from_errno (int err) { - int idx = errno_to_idx (err); + int idx; if (!err) return GPG_ERR_NO_ERROR; + idx = errno_to_idx (err); + + if (idx < 0) + return GPG_ERR_UNKNOWN_ERRNO; + + return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx]; +} + + +/* Retrieve the error code directly from the ERRNO variable. This + returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped + (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */ +gpg_err_code_t +gpg_err_code_from_syserror (void) +{ + int err = errno; + int idx; + + if (!err) + return GPG_ERR_MISSING_ERRNO; + + idx = errno_to_idx (err); + if (idx < 0) return GPG_ERR_UNKNOWN_ERRNO; |