summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Makefile.am17
-rw-r--r--src/code-from-errno.c41
-rw-r--r--src/code-to-errno.c42
-rw-r--r--src/err-codes.h.in1
-rw-r--r--src/errnos.in170
-rw-r--r--src/gpg-error.h164
-rw-r--r--src/mkerrcodes1.awk87
-rw-r--r--src/mkerrcodes2.awk136
-rw-r--r--src/mkerrnos.awk94
-rw-r--r--src/strerror.c9
10 files changed, 754 insertions, 7 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 653e15b..105e40e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,9 +17,10 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in
-BUILT_SOURCES = err-sources.h err-codes.h
-CLEANFILES = err-sources.h err-codes.h
+EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in \
+ mkerrnos.awk errnos.in mkerrcodes1.awk mkerrcodes2.awk
+BUILT_SOURCES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h
+CLEANFILES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h
include_HEADERS = gpg-error.h
@@ -29,7 +30,7 @@ libgpg_error_la_LDFLAGS = -version-info \
@LIBGPG_ERROR_LT_CURRENT@:@LIBGPG_ERROR_LT_REVISION@:@LIBGPG_ERROR_LT_AGE@
libgpg_error_la_SOURCES = gpg-error.h gettext.h \
- err-sources.h strsource.c err-codes.h strerror.c
+ strsource.c strerror.c code-to-errno.c code-from-errno.c
libgpg_error_la_LIBADD = @LTLIBINTL@
@@ -38,3 +39,11 @@ err-sources.h: Makefile mkstrtable.awk err-sources.h.in
err-codes.h: Makefile mkstrtable.awk err-codes.h.in
$(AWK) -f $(srcdir)/mkstrtable.awk $(srcdir)/err-codes.h.in >$@
+
+code-to-errno.h: Makefile mkerrnos.awk errnos.in
+ $(AWK) -f $(srcdir)/mkerrnos.awk $(srcdir)/errnos.in >$@
+
+code-from-errno.h: Makefile mkerrcodes1.awk errnos.in
+ $(AWK) -f $(srcdir)/mkerrcodes1.awk $(srcdir)/errnos.in \
+ | $(CPP) - | grep GPG_ERR_ | sort -n \
+ | $(AWK) -f $(srcdir)/mkerrcodes2.awk >$@
diff --git a/src/code-from-errno.c b/src/code-from-errno.c
new file mode 100644
index 0000000..5312389
--- /dev/null
+++ b/src/code-from-errno.c
@@ -0,0 +1,41 @@
+/* code-from-errno.c - Mapping errnos to error codes.
+ 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-from-errno.h"
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gpg_err_code_t
+gpg_err_code_from_errno (int err)
+{
+ int idx = errno_to_idx (err);
+
+ if (idx < 0)
+ return GPG_ERR_UNKNOWN_ERRNO;
+
+ return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx];
+}
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;
+}
diff --git a/src/err-codes.h.in b/src/err-codes.h.in
index 982005b..474f1c3 100644
--- a/src/err-codes.h.in
+++ b/src/err-codes.h.in
@@ -166,5 +166,6 @@
211 Bad hexadecimal character in S-expression
212 Odd hexadecimal numbers in S-expression
213 Bad octadecimal character in S-expression
+16382 Unknown system error
16383 End of file
Unknown error code
diff --git a/src/errnos.in b/src/errnos.in
new file mode 100644
index 0000000..a12e223
--- /dev/null
+++ b/src/errnos.in
@@ -0,0 +1,170 @@
+# errnos.h.in - List of system error values input file.
+/* errnos.h - List of system error values.
+ 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. */
+
+#include <errno.h>
+
+# Everything up to the first line that starts with an "E" in the first
+# column is copied into the output verbatim. Then, empty lines are
+# ignored. Other lines must have an error name, like EINT. Please
+# note that the order must be the same as the corresponding macros in
+# the gpg_err_code_t type.
+
+E2BIG
+EACCES
+EADDRINUSE
+EADDRNOTAVAIL
+EADV
+EAFNOSUPPORT
+EAGAIN
+EALREADY
+EAUTH
+EBACKGROUND
+EBADE
+EBADF
+EBADFD
+EBADMSG
+EBADR
+EBADRPC
+EBADRQC
+EBADSLT
+EBFONT
+EBUSY
+ECANCELED
+ECHILD
+ECHRNG
+ECOMM
+ECONNABORTED
+ECONNREFUSED
+ECONNRESET
+ED
+EDEADLK
+EDEADLOCK
+EDESTADDRREQ
+EDIED
+EDOM
+EDOTDOT
+EDQUOT
+EEXIST
+EFAULT
+EFBIG
+EFTYPE
+EGRATUITOUS
+EGREGIOUS
+EHOSTDOWN
+EHOSTUNREACH
+EIDRM
+EIEIO
+EILSEQ
+EINPROGRESS
+EINTR
+EINVAL
+EIO
+EISCONN
+EISDIR
+EISNAM
+EL2HLT
+EL2NSYNC
+EL3HLT
+EL3RST
+ELIBACC
+ELIBBAD
+ELIBEXEC
+ELIBMAX
+ELIBSCN
+ELNRNG
+ELOOP
+EMEDIUMTYPE
+EMFILE
+EMLINK
+EMSGSIZE
+EMULTIHOP
+ENAMETOOLONG
+ENAVAIL
+ENEEDAUTH
+ENETDOWN
+ENETRESET
+ENETUNREACH
+ENFILE
+ENOANO
+ENOBUFS
+ENOCSI
+ENODATA
+ENODEV
+ENOENT
+ENOEXEC
+ENOLCK
+ENOLINK
+ENOMEDIUM
+ENOMEM
+ENOMSG
+ENONET
+ENOPKG
+ENOPROTOOPT
+ENOSPC
+ENOSR
+ENOSTR
+ENOSYS
+ENOTBLK
+ENOTCONN
+ENOTDIR
+ENOTEMPTY
+ENOTNAM
+ENOTSOCK
+ENOTSUP
+ENOTTY
+ENOTUNIQ
+ENXIO
+EOPNOTSUPP
+EOVERFLOW
+EPERM
+EPFNOSUPPORT
+EPIPE
+EPROCLIM
+EPROCUNAVAIL
+EPROGMISMATCH
+EPROGUNAVAIL
+EPROTO
+EPROTONOSUPPORT
+EPROTOTYPE
+ERANGE
+EREMCHG
+EREMOTE
+EREMOTEIO
+ERESTART
+EROFS
+ERPCMISMATCH
+ESHUTDOWN
+ESOCKTNOSUPPORT
+ESPIPE
+ESRCH
+ESRMNT
+ESTALE
+ESTRPIPE
+ETIME
+ETIMEDOUT
+ETOOMANYREFS
+ETXTBSY
+EUCLEAN
+EUNATCH
+EUSERS
+EWOULDBLOCK
+EXDEV
+EXFULL
diff --git a/src/gpg-error.h b/src/gpg-error.h
index 938bf6e..fdf4c58 100644
--- a/src/gpg-error.h
+++ b/src/gpg-error.h
@@ -213,10 +213,154 @@ typedef enum
GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212,
GPG_ERR_SEXP_BAD_OCT_CHAR = 213,
+ GPG_ERR_UNKNOWN_ERRNO = 16382,
GPG_ERR_EOF = 16383, /* This was once a -1. Pity. */
+ /* The following error codes are used to map system errors. */
+ GPG_ERR_E2BIG = 16384,
+ GPG_ERR_EACCES = 16385,
+ GPG_ERR_EADDRINUSE = 16386,
+ GPG_ERR_EADDRNOTAVAIL = 16387,
+ GPG_ERR_EADV = 16388,
+ GPG_ERR_EAFNOSUPPORT = 16389,
+ GPG_ERR_EAGAIN = 16390,
+ GPG_ERR_EALREADY = 16391,
+ GPG_ERR_EAUTH = 16392,
+ GPG_ERR_EBACKGROUND = 16393,
+ GPG_ERR_EBADE = 16394,
+ GPG_ERR_EBADF = 16395,
+ GPG_ERR_EBADFD = 16396,
+ GPG_ERR_EBADMSG = 16397,
+ GPG_ERR_EBADR = 16398,
+ GPG_ERR_EBADRPC = 16399,
+ GPG_ERR_EBADRQC = 16400,
+ GPG_ERR_EBADSLT = 16401,
+ GPG_ERR_EBFONT = 16402,
+ GPG_ERR_EBUSY = 16403,
+ GPG_ERR_ECANCELED = 16404,
+ GPG_ERR_ECHILD = 16405,
+ GPG_ERR_ECHRNG = 16406,
+ GPG_ERR_ECOMM = 16407,
+ GPG_ERR_ECONNABORTED = 16408,
+ GPG_ERR_ECONNREFUSED = 16409,
+ GPG_ERR_ECONNRESET = 16410,
+ GPG_ERR_ED = 16411,
+ GPG_ERR_EDEADLK = 16412,
+ GPG_ERR_EDEADLOCK = 16413,
+ GPG_ERR_EDESTADDRREQ = 16414,
+ GPG_ERR_EDIED = 16415,
+ GPG_ERR_EDOM = 16416,
+ GPG_ERR_EDOTDOT = 16417,
+ GPG_ERR_EDQUOT = 16418,
+ GPG_ERR_EEXIST = 16419,
+ GPG_ERR_EFAULT = 16420,
+ GPG_ERR_EFBIG = 16421,
+ GPG_ERR_EFTYPE = 16422,
+ GPG_ERR_EGRATUITOUS = 16423,
+ GPG_ERR_EGREGIOUS = 16424,
+ GPG_ERR_EHOSTDOWN = 16425,
+ GPG_ERR_EHOSTUNREACH = 16426,
+ GPG_ERR_EIDRM = 16427,
+ GPG_ERR_EIEIO = 16428,
+ GPG_ERR_EILSEQ = 16429,
+ GPG_ERR_EINPROGRESS = 16430,
+ GPG_ERR_EINTR = 16431,
+ GPG_ERR_EINVAL = 16432,
+ GPG_ERR_EIO = 16433,
+ GPG_ERR_EISCONN = 16434,
+ GPG_ERR_EISDIR = 16435,
+ GPG_ERR_EISNAM = 16436,
+ GPG_ERR_EL2HLT = 16437,
+ GPG_ERR_EL2NSYNC = 16438,
+ GPG_ERR_EL3HLT = 16439,
+ GPG_ERR_EL3RST = 16440,
+ GPG_ERR_ELIBACC = 16441,
+ GPG_ERR_ELIBBAD = 16442,
+ GPG_ERR_ELIBEXEC = 16443,
+ GPG_ERR_ELIBMAX = 16444,
+ GPG_ERR_ELIBSCN = 16445,
+ GPG_ERR_ELNRNG = 16446,
+ GPG_ERR_ELOOP = 16447,
+ GPG_ERR_EMEDIUMTYPE = 16448,
+ GPG_ERR_EMFILE = 16449,
+ GPG_ERR_EMLINK = 16450,
+ GPG_ERR_EMSGSIZE = 16451,
+ GPG_ERR_EMULTIHOP = 16452,
+ GPG_ERR_ENAMETOOLONG = 16453,
+ GPG_ERR_ENAVAIL = 16454,
+ GPG_ERR_ENEEDAUTH = 16455,
+ GPG_ERR_ENETDOWN = 16456,
+ GPG_ERR_ENETRESET = 16457,
+ GPG_ERR_ENETUNREACH = 16458,
+ GPG_ERR_ENFILE = 16459,
+ GPG_ERR_ENOANO = 16460,
+ GPG_ERR_ENOBUFS = 16461,
+ GPG_ERR_ENOCSI = 16462,
+ GPG_ERR_ENODATA = 16463,
+ GPG_ERR_ENODEV = 16464,
+ GPG_ERR_ENOENT = 16465,
+ GPG_ERR_ENOEXEC = 16466,
+ GPG_ERR_ENOLCK = 16467,
+ GPG_ERR_ENOLINK = 16468,
+ GPG_ERR_ENOMEDIUM = 16469,
+ GPG_ERR_ENOMEM = 16470,
+ GPG_ERR_ENOMSG = 16471,
+ GPG_ERR_ENONET = 16472,
+ GPG_ERR_ENOPKG = 16473,
+ GPG_ERR_ENOPROTOOPT = 16474,
+ GPG_ERR_ENOSPC = 16475,
+ GPG_ERR_ENOSR = 16476,
+ GPG_ERR_ENOSTR = 16477,
+ GPG_ERR_ENOSYS = 16478,
+ GPG_ERR_ENOTBLK = 16479,
+ GPG_ERR_ENOTCONN = 16480,
+ GPG_ERR_ENOTDIR = 16481,
+ GPG_ERR_ENOTEMPTY = 16482,
+ GPG_ERR_ENOTNAM = 16483,
+ GPG_ERR_ENOTSOCK = 16484,
+ GPG_ERR_ENOTSUP = 16485,
+ GPG_ERR_ENOTTY = 16486,
+ GPG_ERR_ENOTUNIQ = 16487,
+ GPG_ERR_ENXIO = 16488,
+ GPG_ERR_EOPNOTSUPP = 16489,
+ GPG_ERR_EOVERFLOW = 16490,
+ GPG_ERR_EPERM = 16491,
+ GPG_ERR_EPFNOSUPPORT = 16492,
+ GPG_ERR_EPIPE = 16493,
+ GPG_ERR_EPROCLIM = 16494,
+ GPG_ERR_EPROCUNAVAIL = 16495,
+ GPG_ERR_EPROGMISMATCH = 16496,
+ GPG_ERR_EPROGUNAVAIL = 16497,
+ GPG_ERR_EPROTO = 16498,
+ GPG_ERR_EPROTONOSUPPORT = 16499,
+ GPG_ERR_EPROTOTYPE = 16500,
+ GPG_ERR_ERANGE = 16501,
+ GPG_ERR_EREMCHG = 16502,
+ GPG_ERR_EREMOTE = 16503,
+ GPG_ERR_EREMOTEIO = 16504,
+ GPG_ERR_ERESTART = 16505,
+ GPG_ERR_EROFS = 16506,
+ GPG_ERR_ERPCMISMATCH = 16507,
+ GPG_ERR_ESHUTDOWN = 16508,
+ GPG_ERR_ESOCKTNOSUPPORT = 16509,
+ GPG_ERR_ESPIPE = 16510,
+ GPG_ERR_ESRCH = 16511,
+ GPG_ERR_ESRMNT = 16512,
+ GPG_ERR_ESTALE = 16513,
+ GPG_ERR_ESTRPIPE = 16514,
+ GPG_ERR_ETIME = 16515,
+ GPG_ERR_ETIMEDOUT = 16516,
+ GPG_ERR_ETOOMANYREFS = 16517,
+ GPG_ERR_ETXTBSY = 16518,
+ GPG_ERR_EUCLEAN = 16519,
+ GPG_ERR_EUNATCH = 16520,
+ GPG_ERR_EUSERS = 16521,
+ GPG_ERR_EWOULDBLOCK = 16522,
+ GPG_ERR_EXDEV = 16523,
+ GPG_ERR_EXFULL = 16524,
+
/* This is one more than the largest allowed entry. */
- GPG_ERR_CODE_DIM = 16384
+ GPG_ERR_CODE_DIM = 32768
} gpg_err_code_t;
@@ -228,10 +372,12 @@ typedef enum
-freg-struct-return option to GCC). */
typedef unsigned int gpg_error_t;
-/* We use the lowest 16 bits of gpg_error_t for error codes. */
+/* We use the lowest 16 bits of gpg_error_t for error codes. The 17th
+ bit indicates system errors. */
#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
+#define GPG_ERR_SYSTEM_ERROR 16384
-/* Bits 17 to 24 are reserved. */
+/* Bits 18 to 24 are reserved. */
/* We use the upper 8 bits of gpg_error_t for error sources. */
#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
@@ -290,4 +436,16 @@ const char *gpg_strerror (gpg_error_t err);
source in the error value ERR. */
const char *gpg_strsource (gpg_error_t err);
+
+/* Mapping of system errors (errno). */
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gpg_err_code_t gpg_err_code_from_errno (int err);
+
+/* 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);
+
#endif /* GPG_ERROR_H */
diff --git a/src/mkerrcodes1.awk b/src/mkerrcodes1.awk
new file mode 100644
index 0000000..d666f51
--- /dev/null
+++ b/src/mkerrcodes1.awk
@@ -0,0 +1,87 @@
+# mkerrcodes.awk
+# 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 General Public License as
+# published by the Free Software Foundation; either version 2 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with libgnupg-error; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+#
+# As a special exception, g10 Code GmbH gives unlimited permission to
+# copy, distribute and modify the C source files that are the output
+# of mkerrcodes.awk. You need not follow the terms of the GNU General
+# Public License when using or distributing such scripts, even though
+# portions of the text of mkerrcodes.awk appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the mkerrcodes.awk program.
+#
+# Certain portions of the mkerrcodes.awk source text are designed to be
+# copied (in certain cases, depending on the input) into the output of
+# mkerrcodes.awk. We call these the "data" portions. The rest of the
+# mkerrcodes.awk source text consists of comments plus executable code
+# that decides which of the data portions to output in any given case.
+# We call these comments and executable code the "non-data" portions.
+# mkerrcodes.h never copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of mkerrcodes.awk
+# released by g10 Code GmbH. When you make and distribute a modified version
+# of mkerrcodes.awk, you may extend this special exception to the GPL to
+# apply to your modified version as well, *unless* your modified version
+# has the potential to copy into its output some of the text that was the
+# non-data portion of the version that you started with. (In other words,
+# unless your change moves or copies text from the non-data portions to the
+# data portions.) If your modification has such potential, you must delete
+# any notice of this special exception to the GPL from your modified version.
+
+# This script outputs an intermediate file that contains the following block
+# for each error value symbol in the input file (example for EINVAL):
+#
+# #ifdef EINVAL
+# EINVAL GPG_ERR_EINVAL
+# #endif
+#
+# The input file is a list of possible system errors.
+#
+# Comments (starting with # and ending at the end of the line) are removed,
+# as is trailing whitespace.
+
+BEGIN {
+ print "/* Output of mkerrcodes.awk. DO NOT EDIT. */";
+ print "";
+ header = 1;
+}
+
+/^#/ { next; }
+
+header {
+ if ($1 ~ /^E/)
+ {
+ print "#include <errno.h>";
+ print "";
+ header = 0;
+ }
+ else
+ print;
+}
+
+!header {
+ sub (/\#.+/, "");
+ sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
+
+ if (/^$/)
+ next;
+
+ print "#ifdef " $1;
+ print $1 " GPG_ERR_" $1;
+ print "#endif";
+}
diff --git a/src/mkerrcodes2.awk b/src/mkerrcodes2.awk
new file mode 100644
index 0000000..54a0d18
--- /dev/null
+++ b/src/mkerrcodes2.awk
@@ -0,0 +1,136 @@
+# mkstrtable.awk
+# 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 General Public License as
+# published by the Free Software Foundation; either version 2 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with libgnupg-error; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+#
+# As a special exception, g10 Code GmbH gives unlimited permission to
+# copy, distribute and modify the C source files that are the output
+# of mkerrcodes2.awk. You need not follow the terms of the GNU General
+# Public License when using or distributing such scripts, even though
+# portions of the text of mkerrcodes2.awk appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the mkerrcodes2.awk program.
+#
+# Certain portions of the mkerrcodes2.awk source text are designed to be
+# copied (in certain cases, depending on the input) into the output of
+# mkerrcodes2.awk. We call these the "data" portions. The rest of the
+# mkerrcodes2.awk source text consists of comments plus executable code
+# that decides which of the data portions to output in any given case.
+# We call these comments and executable code the "non-data" portions.
+# mkstrtable.h never copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of mkerrcodes2.awk
+# released by g10 Code GmbH. When you make and distribute a modified version
+# of mkerrcodes2.awk, you may extend this special exception to the GPL to
+# apply to your modified version as well, *unless* your modified version
+# has the potential to copy into its output some of the text that was the
+# non-data portion of the version that you started with. (In other words,
+# unless your change moves or copies text from the non-data portions to the
+# data portions.) If your modification has such potential, you must delete
+# any notice of this special exception to the GPL from your modified version.
+
+# This script outputs a source file that does define the following
+# symbols:
+#
+# static const char msgstr[];
+# A string containing all messages in the list.
+#
+# static const int msgidx[];
+# A list of index numbers, one for each message, that points to the
+# beginning of the string in msgstr.
+#
+# msgidxof (code);
+# A macro that maps code numbers to idx numbers. If a DEFAULT MESSAGE
+# is provided (see below), its index will be returned for unknown codes.
+# Otherwise -1 is returned for codes that do not appear in the list.
+# You can lookup the message with code CODE with:
+# msgstr + msgidx[msgidxof (code)].
+#
+# The input file has the following format:
+# CODE1 MESSAGE1 (Code number, <tab>, message string)
+# CODE2 MESSAGE2 (Code number, <tab>, message string)
+# ...
+# CODEn MESSAGEn (Code number, <tab>, message string)
+# DEFAULT MESSAGE (<tab>, fall-back message string)
+#
+# Comments (starting with # and ending at the end of the line) are removed,
+# as is trailing whitespace. The last line is optional; if no DEFAULT
+# MESSAGE is given, msgidxof will return the number -1 for unknown
+# index numbers.
+
+BEGIN {
+# msg holds the number of messages.
+ msg = 0;
+ print "/* Output of mkerrcodes2.awk. DO NOT EDIT. */";
+ print "";
+ header = 1;
+}
+
+/^#/ { next; }
+
+header {
+ if ($1 ~ /^[0123456789]+$/)
+ {
+ print "static const int err_code_from_index[] = {";
+ header = 0;
+ }
+ else
+ print;
+}
+
+!header {
+ sub (/\#.+/, "");
+ sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
+
+ if (/^$/)
+ next;
+
+# Print the string msgstr line by line. We delay output by one line to be able
+# to treat the last line differently (see END).
+ print " " $2 ",";
+
+# Remember the error value and index of each error code.
+ code[msg] = $1;
+ pos[msg] = $2;
+ msg++;
+}
+END {
+ print "};";
+ print "";
+ print "#define errno_to_idx(code) (0 ? -1 \\";
+
+# Gather the ranges.
+ skip = code[0];
+ start = code[0];
+ stop = code[0];
+ for (i = 1; i < msg; i++)
+ {
+ if (code[i] == stop + 1)
+ stop++;
+ else
+ {
+ print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \
+ skip ") \\";
+ skip += code[i] - stop - 1;
+ start = code[i];
+ stop = code[i];
+ }
+ }
+ print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \
+ skip ") \\";
+ print " : -1)";
+}
diff --git a/src/mkerrnos.awk b/src/mkerrnos.awk
new file mode 100644
index 0000000..2f5fec2
--- /dev/null
+++ b/src/mkerrnos.awk
@@ -0,0 +1,94 @@
+# mkerrnos.awk
+# 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 General Public License as
+# published by the Free Software Foundation; either version 2 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with libgnupg-error; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+#
+# As a special exception, g10 Code GmbH gives unlimited permission to
+# copy, distribute and modify the C source files that are the output
+# of mkerrnos.awk. You need not follow the terms of the GNU General
+# Public License when using or distributing such scripts, even though
+# portions of the text of mkerrnos.awk appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the mkerrnos.awk program.
+#
+# Certain portions of the mkerrnos.awk source text are designed to be
+# copied (in certain cases, depending on the input) into the output of
+# mkerrnos.awk. We call these the "data" portions. The rest of the
+# mkerrnos.awk source text consists of comments plus executable code
+# that decides which of the data portions to output in any given case.
+# We call these comments and executable code the "non-data" portions.
+# mkerrnos.h never copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of mkerrnos.awk
+# released by g10 Code GmbH. When you make and distribute a modified version
+# of mkerrnos.awk, you may extend this special exception to the GPL to
+# apply to your modified version as well, *unless* your modified version
+# has the potential to copy into its output some of the text that was the
+# non-data portion of the version that you started with. (In other words,
+# unless your change moves or copies text from the non-data portions to the
+# data portions.) If your modification has such potential, you must delete
+# any notice of this special exception to the GPL from your modified version.
+
+# This script outputs a source file that does define the following
+# symbols:
+#
+# static const int err_code_to_errno[];
+# A mapping of gpg_err_code_t numbers to system errno. The index of an
+# error code in the table can be obtained after removing the system error
+# code indication bit.
+#
+# The input file is a list of possible system errors.
+#
+# Comments (starting with # and ending at the end of the line) are removed,
+# as is trailing whitespace.
+
+BEGIN {
+ print "/* Output of mkerrnos.awk. DO NOT EDIT. */";
+ print "";
+ header = 1;
+}
+
+/^#/ { next; }
+
+header {
+ if ($1 ~ /^E/)
+ {
+ print "#include <errno.h>";
+ print "";
+ print "static const int err_code_to_errno [] = {";
+ header = 0;
+ }
+ else
+ print;
+}
+
+!header {
+ sub (/\#.+/, "");
+ sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
+
+ if (/^$/)
+ next;
+
+ print "#ifdef " $1;
+ print " " $1 ",";
+ print "#else";
+ print " 0,";
+ print "#endif";
+}
+END {
+ print "};";
+}
diff --git a/src/strerror.c b/src/strerror.c
index f0fb9e9..3e627b1 100644
--- a/src/strerror.c
+++ b/src/strerror.c
@@ -33,5 +33,14 @@ const char *
gpg_strerror (gpg_error_t err)
{
gpg_err_code_t code = gpg_err_code (err);
+
+ if (code & GPG_ERR_SYSTEM_ERROR)
+ {
+ int no = gpg_err_code_to_errno (err);
+ if (no)
+ return strerror (no);
+ else
+ code = GPG_ERR_UNKNOWN_ERRNO;
+ }
return dgettext (PACKAGE, msgstr + msgidx[msgidxof (code)]);
}