summaryrefslogtreecommitdiff
path: root/src/code-from-errno.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2006-09-14 14:24:34 +0000
committerWerner Koch <wk@gnupg.org>2006-09-14 14:24:34 +0000
commit12172fa6fa5136cfaa8eca23cb83840386a3892f (patch)
tree8261c598e67f51dd708bc9b2a11f56704e2db224 /src/code-from-errno.c
parent1a01e7ec9f4943367ed27330017f52a1bf2cbaa5 (diff)
downloadlibgpg-error-12172fa6fa5136cfaa8eca23cb83840386a3892f.tar.gz
Ready for a new releaselibgpg-error-1.4
Diffstat (limited to 'src/code-from-errno.c')
-rw-r--r--src/code-from-errno.c27
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;