summaryrefslogtreecommitdiff
path: root/src/code-to-errno.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <mb@g10code.com>2003-06-01 21:11:40 +0000
committerMarcus Brinkmann <mb@g10code.com>2003-06-01 21:11:40 +0000
commit85fee89a19a7e9657f9d76949bcdbf4b6c42d182 (patch)
treecd16f5ebef862ca1516f8baf6b359f602d0a0a39 /src/code-to-errno.c
parent1316051181294dc4398fcb31b27e7389b32f079f (diff)
downloadlibgpg-error-85fee89a19a7e9657f9d76949bcdbf4b6c42d182.tar.gz
2003-06-01 Marcus Brinkmann <marcus@g10code.de>
* src/mkerrcodes1.awk: New file. * src/mkerrcodes2.awk: New file. * src/mkerrnos.awk: New file. * src/errnos.in: New file. * src/code-from-errno.c: New file. * src/code-to-errno.c: New file. * src/Makefile.am (libgpg_error_la_SOURCES): Remove err-sources.h and err-codes.h. Add code-to-errno.c and code-from-errno.c. (code-to-errno.h): New target. (code-from-errno.h): Likewise. (EXTRA_DIST): Add mkerrnos.awk, errnos.in, and mkerrcodes1.awk. (BUILT_SOURCES): Add code-to-errno.h and code-from-errno.h. (CLEANFILES): Likewise. * src/strerror.c (gpg_strerror): Use strerror for system errors. * src/err-codes.h.in: Add 16382 (Unknown system error). * src/gpg-error.h (gpg_err_code_t): Add system errors. (GPG_ERR_CODE_DIM): Change to 32768. (GPG_ERR_SYSTEM_ERROR): New macro. (gpg_err_code_from_errno): New prototype. (gpg_err_code_to_errno): Likewise.
Diffstat (limited to 'src/code-to-errno.c')
-rw-r--r--src/code-to-errno.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/code-to-errno.c b/src/code-to-errno.c
new file mode 100644
index 0000000..b8253c7
--- /dev/null
+++ b/src/code-to-errno.c
@@ -0,0 +1,42 @@
+/* code-to-errno.c - Mapping error codes to errnos.
+ Copyright (C) 2003 g10 Code GmbH
+
+ This file is part of libgpg-error.
+
+ libgpg-error is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ libgpg-error is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with libgpgme-error; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gpg-error.h>
+
+#include "code-to-errno.h"
+
+/* Retrieve the system error for the error code ERR. This returns 0
+ if ERR is not a system error code. */
+int
+gpg_err_code_to_errno (gpg_err_code_t code)
+{
+ if (!(code & GPG_ERR_SYSTEM_ERROR))
+ return 0;
+ code &= ~GPG_ERR_SYSTEM_ERROR;
+
+ if (code < sizeof (err_code_to_errno) / sizeof (err_code_to_errno[0]))
+ return err_code_to_errno[code];
+ else
+ return 0;
+}