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. --- src/init.c | 93 +++++++++----------------------------------------------------- 1 file changed, 13 insertions(+), 80 deletions(-) (limited to 'src/init.c') 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*/ -- cgit v1.2.3