From eaec10f48803ee2232d1c1515fbe8f485c1e84b0 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 10 Apr 2015 10:52:24 +0200 Subject: w32: Remove compiler warnings. * src/Makefile.am (pre_mkheader_cmds): Avoid make diagnostic about failed but ignored command. This confuses Emacs' compiler job parser. * tests/t-lock.c [W32]: Include time.h. * src/init.c: Reorganize Windows only code. (wchar_to_utf8, utf8_to_wchar): Remove unused functions. (_gpg_err_set_errno): Use only one copy for all platforms. -- Note that there is a still a problem for W64 pertaining to the use of an int to store a HANDLE. This will be fixed when we add a full abstraction layer for Windows file objects. --- doc/errorref.txt | 8 ++++- src/Makefile.am | 3 +- src/init.c | 93 ++++++++------------------------------------------------ tests/t-lock.c | 1 + 4 files changed, 23 insertions(+), 82 deletions(-) diff --git a/doc/errorref.txt b/doc/errorref.txt index 0393f16..2ee1aa4 100644 --- a/doc/errorref.txt +++ b/doc/errorref.txt @@ -282,7 +282,13 @@ GPG_ERR_INV_DATA Invalid data expected. 80 GPG_ERR_ASSUAN_SERVER_FAULT Unspecific Assuan server fault -81 GPG_ERR_ASSUAN General Assuan error + +GPG_ERR_ASSUAN General Assuan error + + GNUPG: - Used by Assuan command handler if they fail to do basic + things like an es_fdopen or es_fopencookie. + + 82 GPG_ERR_INV_SESSION_KEY Invalid session key 83 GPG_ERR_INV_SEXP Invalid S-expression 84 GPG_ERR_UNSUPPORTED_ALGORITHM Unsupported algorithm diff --git a/src/Makefile.am b/src/Makefile.am index f847a80..e038d7f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -276,7 +276,8 @@ parts_of_gpg_error_h = \ # If we are cross-compiling or building on Windows we better make sure # that no stale native lock include file will be found by mkheader. if FORCE_USE_SYSCFG -pre_mkheader_cmds = -rm lock-obj-pub.native.h 2>/dev/null +pre_mkheader_cmds = if test -f lock-obj-pub.native.h; \ + then rm lock-obj-pub.native.h; fi else pre_mkheader_cmds = : parts_of_gpg_error_h += ./lock-obj-pub.native.h diff --git a/src/init.c b/src/init.c index 6305fe3..e84b234 100644 --- a/src/init.c +++ b/src/init.c @@ -202,70 +202,22 @@ _gpgrt_free (void *a) } - - -#ifdef HAVE_W32_SYSTEM - -/* 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) +void +_gpg_err_set_errno (int err) { - 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; +#ifdef HAVE_W32CE_SYSTEM + SetLastError (err); +#else /*!HAVE_W32CE_SYSTEM*/ + errno = err; +#endif /*!HAVE_W32CE_SYSTEM*/ } -/* 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; -} - + +#ifdef HAVE_W32_SYSTEM +/***************************************** + ******** Below is only Windows code. **** + *****************************************/ static char * get_locale_dir (void) @@ -419,17 +371,6 @@ _gpg_w32ce_strerror (int err) #endif /*HAVE_W32CE_SYSTEM*/ -void -_gpg_err_set_errno (int err) -{ -#ifdef HAVE_W32CE_SYSTEM - SetLastError (err); -#else /*!HAVE_W32CE_SYSTEM*/ - errno = err; -#endif /*!HAVE_W32CE_SYSTEM*/ -} - - /* Entry point called by the DLL loader. */ #ifdef DLL_EXPORT int WINAPI @@ -483,12 +424,4 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved) } #endif /*DLL_EXPORT*/ -#else /*!HAVE_W32_SYSTEM*/ - -void -_gpg_err_set_errno (int err) -{ - errno = err; -} - -#endif /*!HAVE_W32_SYSTEM*/ +#endif /*HAVE_W32_SYSTEM*/ diff --git a/tests/t-lock.c b/tests/t-lock.c index 5a21666..fd645eb 100644 --- a/tests/t-lock.c +++ b/tests/t-lock.c @@ -29,6 +29,7 @@ #include #ifdef _WIN32 # include +# include #else # include #endif -- cgit v1.2.3