diff options
author | Werner Koch <[email protected]> | 2010-01-18 20:14:25 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2010-01-18 20:14:25 +0000 |
commit | e4da3564e0dee1dfd39ac7891dad8d2fb7cd6be0 (patch) | |
tree | 7deee1221410c3801c0ef298f0a00ac6689a6cad /src | |
parent | Add some code to build nativley under WindowsCE - not finished. (diff) | |
download | libgpg-error-e4da3564e0dee1dfd39ac7891dad8d2fb7cd6be0.tar.gz libgpg-error-e4da3564e0dee1dfd39ac7891dad8d2fb7cd6be0.zip |
Fix w32ce strerror.
Fix non-w32ce dependency problem.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gpg-error.c | 40 | ||||
-rw-r--r-- | src/gpg-extra/errno.h | 60 | ||||
-rw-r--r-- | src/init.c | 89 |
4 files changed, 120 insertions, 71 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8e2a319..d948021 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in \ 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 diff --git a/src/gpg-error.c b/src/gpg-error.c index eefd672..6cfe292 100644 --- a/src/gpg-error.c +++ b/src/gpg-error.c @@ -462,6 +462,10 @@ int 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 @@ main (int argc, char *argv[]) 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), diff --git a/src/gpg-extra/errno.h b/src/gpg-extra/errno.h deleted file mode 100644 index 7670fda..0000000 --- a/src/gpg-extra/errno.h +++ /dev/null @@ -1,60 +0,0 @@ -/* errno.h - WindowsCE errno.h substitute - Copyright (C) 2010 g10 Code GmbH - - This file is free software; as a special exception the author gives - unlimited permission to copy and/or distribute it, with or without - modifications, as long as this notice is preserved. - - This file is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY, to the extent permitted by law; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. - - +++ Do not edit! File has been generated by mkw32errmap.c +++ - - This file is intended to be used with ming32ce-gcc to implement an - errno substitute under WindowsCE. It must be included via gcc's - -idirafter option. The gpg-error-config script emits the - appropriate option snippet. The actual implementation of the errno - related functions are part of libgpg-error. A separate header file - is required because errno.h is often included before gpg-error.h. - */ - -#ifndef _GPG_ERROR_EXTRA_ERRNO_H -#define _GPG_ERROR_EXTRA_ERRNO_H - -/* Due to peculiarities in W32 we can't implement ERRNO as an - writable lvalue. This also allows us to easily find places - where ERRNO is being written to. See also gpg_err_set_errno. */ -int _gpg_w32ce_get_errno (void); -#define errno (_gpg_w32ce_get_errno ()) - -#define ENOENT 2 -#define EMFILE 4 -#define EACCES 5 -#define EBADF 6 -#define ENOMEM 8 -#define EXDEV 17 -#define ENFILE 18 -#define EROFS 19 -#define ENOLCK 36 -#define ENOSYS 50 -#define EEXIST 80 -#define EPERM 82 -#define EINVAL 87 -#define EINTR 104 -#define EPIPE 109 -#define ENOSPC 112 -#define ENOTEMPTY 145 -#define EBUSY 170 -#define ENAMETOOLONG 206 -#define EAGAIN 234 -#define ENOTDIR 267 -#define ERANGE 534 -#define ENXIO 1006 -#define EFAULT 1067 -#define EIO 1117 -#define EDEADLOCK 1131 -#define ENODEV 1200 - -#endif /*_GPG_ERROR_EXTRA_ERRNO_H*/ @@ -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 @@ gpg_err_init (void) #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 @@ char * _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; |