[svn] gpg-error - r227 - in trunk: . src src/gpg-extra
svn author wk
cvs at cvs.gnupg.org
Mon Jan 18 21:14:25 CET 2010
Author: wk
Date: 2010-01-18 21:14:25 +0100 (Mon, 18 Jan 2010)
New Revision: 227
Removed:
trunk/src/gpg-extra/errno.h
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/Makefile.am
trunk/src/gpg-error.c
trunk/src/init.c
Log:
Fix w32ce strerror.
Fix non-w32ce dependency problem.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-01-18 15:10:37 UTC (rev 226)
+++ trunk/ChangeLog 2010-01-18 20:14:25 UTC (rev 227)
@@ -1,5 +1,11 @@
2010-01-18 Werner Koch <wk at g10code.com>
+ * src/init.c (wchar_to_utf8, utf8_to_wchar): New.
+
+ * src/gpg-error.c (main): Add option --list.
+
+2010-01-18 Werner Koch <wk at g10code.com>
+
* ltmain.sh (wrappers_required): Don't set for mingw32ce.
* tests/Makefile.am (extra_includes): New.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2010-01-18 15:10:37 UTC (rev 226)
+++ trunk/NEWS 2010-01-18 20:14:25 UTC (rev 227)
@@ -3,6 +3,8 @@
* Preliminary support for WindowsCE.
+ * New option --list for gpg-error.
+
* Interface changes relative to the 1.7 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GPG_ERR_NOT_ENABLED NEW.
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2010-01-18 15:10:37 UTC (rev 226)
+++ trunk/src/Makefile.am 2010-01-18 20:14:25 UTC (rev 227)
@@ -48,7 +48,7 @@
BUILT_SOURCES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h \
err-sources-sym.h err-codes-sym.h errnos-sym.h gpg-error.h \
- gpg-error.def gpg-extra/errno.h extra-h.in
+ gpg-error.def extra-h.in $(extra_headers)
tmp_files = _mkerrcodes.h _gpg-error.def.h mkw32errmap.tab.h
Modified: trunk/src/gpg-error.c
===================================================================
--- trunk/src/gpg-error.c 2010-01-18 15:10:37 UTC (rev 226)
+++ trunk/src/gpg-error.c 2010-01-18 20:14:25 UTC (rev 227)
@@ -462,6 +462,10 @@
main (int argc, char *argv[])
{
int i = 1;
+ int listmode = 0;
+ const char *source_sym;
+ const char *error_sym;
+ gpg_error_t err;
#ifndef GPG_ERR_INITIALIZED
gpg_err_init ();
@@ -481,18 +485,46 @@
fputs ("gpg-error (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stdout);
exit (0);
}
+ else if (argc == 2 && !strcmp (argv[1], "--list"))
+ {
+ listmode = 1;
+ }
+ if (listmode)
+ {
+ for (i=0; i < GPG_ERR_SOURCE_DIM; i++)
+ {
+ /* We use error code 1 because gpg_err_make requires a
+ non-zero error code. */
+ err = gpg_err_make (i, 1);
+ err -= 1;
+ source_sym = gpg_strsource_sym (err);
+ if (source_sym)
+ printf ("%u = (%u, -) = (%s, -) = (%s, -)\n",
+ err, gpg_err_source (err),
+ source_sym, gpg_strsource (err));
+ }
+ for (i=0; i < GPG_ERR_CODE_DIM; i++)
+ {
+ err = gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, i);
+ error_sym = gpg_strerror_sym (err);
+ if (error_sym)
+ printf ("%u = (-, %u) = (-, %s) = (-, %s)\n",
+ err, gpg_err_code (err),
+ error_sym, gpg_strerror (err));
+ }
+
+ i = argc; /* Don't run the usual stuff. */
+ }
while (i < argc)
{
- gpg_error_t err;
-
if (get_err_from_number (argv[i], &err)
|| get_err_from_symbol (argv[i], &err)
|| get_err_from_str (argv[i], &err))
{
- const char *source_sym = gpg_strsource_sym (err);
- const char *error_sym = gpg_strerror_sym (err);
+ source_sym = gpg_strsource_sym (err);
+ error_sym = gpg_strerror_sym (err);
printf ("%u = (%u, %u) = (%s, %s) = (%s, %s)\n",
err, gpg_err_source (err), gpg_err_code (err),
Deleted: trunk/src/gpg-extra/errno.h
Modified: trunk/src/init.c
===================================================================
--- trunk/src/init.c 2010-01-18 15:10:37 UTC (rev 226)
+++ trunk/src/init.c 2010-01-18 20:14:25 UTC (rev 227)
@@ -35,13 +35,16 @@
/* Locale directory support. */
#if HAVE_W32_SYSTEM
+
+/* 119 bytes for an error message should be enough. With this size we
+ can assume that the allocation does not take up more than 128 bytes
+ per thread. */
+#define STRBUFFER_SIZE 120
+
/* The TLS space definition. */
struct tls_space_s
{
- /* 119 bytes for an error message should be enough. With this size
- we can assume that the allocation does not take up more than 128
- bytes per thread. */
- char strerror_buffer[120];
+ char strerror_buffer[STRBUFFER_SIZE];
};
static int tls_index; /* Index for the TLS functions. */
@@ -82,6 +85,68 @@
#include <windows.h>
+/* Return a malloced string encoded in UTF-8 from the wide char input
+ string STRING. Caller must free this value. Returns NULL on
+ failure. Caller may use GetLastError to get the actual error
+ number. The result of calling this function with STRING set to
+ NULL is not defined. */
+static char *
+wchar_to_utf8 (const wchar_t *string)
+{
+ int n;
+ char *result;
+
+ /* Note, that CP_UTF8 is not defined in Windows versions earlier
+ than NT. */
+ n = WideCharToMultiByte (CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
+ if (n < 0)
+ return NULL;
+
+ result = malloc (n+1);
+ if (result)
+ {
+ n = WideCharToMultiByte (CP_UTF8, 0, string, -1, result, n, NULL, NULL);
+ if (n < 0)
+ {
+ free (result);
+ result = NULL;
+ }
+ }
+ return result;
+}
+
+
+/* Return a malloced wide char string from an UTF-8 encoded input
+ string STRING. Caller must free this value. Returns NULL on
+ failure. Caller may use GetLastError to get the actual error
+ number. The result of calling this function with STRING set to
+ NULL is not defined. */
+static wchar_t *
+utf8_to_wchar (const char *string)
+{
+ int n;
+ wchar_t *result;
+
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0);
+ if (n < 0)
+ return NULL;
+
+ result = malloc ((n+1) * sizeof *result);
+ if (result)
+ {
+ n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n);
+ if (n < 0)
+ {
+ free (result);
+ result = NULL;
+ }
+ return NULL;
+ }
+ return result;
+}
+
+
+
static HKEY
get_root_key(const char *root)
{
@@ -295,13 +360,25 @@
_gpg_w32ce_strerror (int err)
{
struct tls_space_s *tls = get_tls ();
+ wchar_t tmpbuf[STRBUFFER_SIZE];
+ int n;
if (err == -1)
err = _gpg_w32ce_get_errno ();
- if (!FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ if (FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- tls->strerror_buffer, sizeof tls->strerror_buffer -1,
+ tmpbuf, STRBUFFER_SIZE -1,
NULL))
+ {
+ n = WideCharToMultiByte (CP_UTF8, 0, tmpbuf, -1,
+ tls->strerror_buffer,
+ sizeof tls->strerror_buffer -1,
+ NULL, NULL);
+ }
+ else
+ n = -1;
+
+ if (n < 0)
snprintf (tls->strerror_buffer, sizeof tls->strerror_buffer -1,
"[w32err=%d]", err);
return tls->strerror_buffer;
More information about the Gnupg-commits
mailing list