From 539705d58fc39a28388ff18c695dd406f4ffd1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Sch=C3=BCmann?= Date: Fri, 20 Mar 2015 12:32:29 +0000 Subject: MirOTR: Libgcrypt and Libgpg-error update Libgcrypt 1.4.6 => 1.6.3 Libgpg-error 1.9 => 1.18 git-svn-id: http://svn.miranda-ng.org/main/trunk@12449 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirOTR/Libgpg-error/w32-gettext.c | 181 +++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 56 deletions(-) (limited to 'plugins/MirOTR/Libgpg-error/w32-gettext.c') diff --git a/plugins/MirOTR/Libgpg-error/w32-gettext.c b/plugins/MirOTR/Libgpg-error/w32-gettext.c index da07a25695..89f505d91d 100644 --- a/plugins/MirOTR/Libgpg-error/w32-gettext.c +++ b/plugins/MirOTR/Libgpg-error/w32-gettext.c @@ -1,19 +1,19 @@ /* w32-gettext.h - A simple gettext implementation for Windows targets. Copyright (C) 1995, 1996, 1997, 1999, 2005, 2007, -2 2008, 2010 Free Software Foundation, Inc. + 2008, 2010 Free Software Foundation, Inc. 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 this program; if not, see . */ @@ -30,8 +30,9 @@ #include #include #include +#ifdef HAVE_SYS_TYPES_H #include -#include +#endif #include #ifndef HAVE_W32CE_SYSTEM # include @@ -50,7 +51,39 @@ #endif /*!jnlib_malloc*/ #include "init.h" +#include "gpg-error.h" + +#ifdef HAVE_W32CE_SYSTEM +/* Forward declaration. */ +static wchar_t *utf8_to_wchar (const char *string, size_t length, size_t *retlen); + +static HANDLE +MyCreateFileA (LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwSharedMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, + HANDLE hTemplateFile) +{ + wchar_t *filename; + HANDLE result; + int err; + size_t size; + + filename = utf8_to_wchar (lpFileName, -1, &size); + if (!filename) + return INVALID_HANDLE_VALUE; + result = CreateFileW (filename, dwDesiredAccess, dwSharedMode, + lpSecurityAttributes, dwCreationDisposition, + dwFlagsAndAttributes, hTemplateFile); + + err = GetLastError (); + free (filename); + SetLastError (err); + return result; +} +#undef CreateFileA +#define CreateFileA MyCreateFileA +#endif /* localname.c from gettext BEGIN. */ @@ -601,8 +634,8 @@ #ifndef SUBLANG_UZBEK_CYRILLIC #define SUBLANG_UZBEK_CYRILLIC 0x02 #endif - -/* Return an XPG style locale name + +/* Return an XPG style locale name language[_territory[.codeset]][@modifier]. Don't even bother determining the codeset; it's not useful in this context, because message catalogs are not specific to a single @@ -611,7 +644,9 @@ static const char * my_nl_locale_name (const char *categoryname) { +#ifndef HAVE_W32CE_SYSTEM const char *retval; +#endif LCID lcid; LANGID langid; int primary, sub; @@ -1026,7 +1061,7 @@ my_nl_locale_name (const char *categoryname) /* Support functions. */ -static __inline__ uint32_t +static GPG_ERR_INLINE uint32_t do_swap_u32 (uint32_t i) { return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); @@ -1041,12 +1076,12 @@ do_swap_u32 (uint32_t i) /* The so called `hashpjw' function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.] */ -static __inline__ unsigned long -hash_string( const char *str_param ) +static GPG_ERR_INLINE unsigned long +hash_string (const char *str_param) { unsigned long int hval, g; const char *str = str_param; - + hval = 0; while (*str != '\0') { @@ -1146,14 +1181,33 @@ static char *current_domainname; -/* Constructor for this module. Called from DllMain. */ -static void module_init (void) __attribute__ ((__constructor__)); +/* Constructor for this module. This can only be used if we are a + DLL. If used as a static lib we can't control the process set; for + example it might be used with a main module which is not build with + mingw and thus does not know how to call the constructors. */ +#ifdef DLL_EXPORT +static void module_init (void) _GPG_ERR_CONSTRUCTOR; +#endif static void module_init (void) { - InitializeCriticalSection (&domainlist_access_cs); + static int init_done; + + if (!init_done) + { + InitializeCriticalSection (&domainlist_access_cs); + init_done = 1; + } } +#if !defined(DLL_EXPORT) || !defined(_GPG_ERR_HAVE_CONSTRUCTOR) +void +_gpg_w32__init_gettext_module (void) +{ + module_init (); +} +#endif + /* Free the domain data. */ static void @@ -1171,35 +1225,33 @@ free_domain (struct loaded_domain *domain) jnlib_free (domain); } - + static struct loaded_domain * load_domain (const char *filename) { - FILE *fp; - size_t size; - struct stat st; + HANDLE fh; + DWORD size; struct mo_file_header *data = NULL; struct loaded_domain *domain = NULL; size_t to_read; char *read_ptr; - - fp = fopen (filename, "rb"); - if (!fp) - { - return NULL; - } - if (fstat (fileno (fp), &st) - || (size = (size_t) st.st_size) != st.st_size - || size < sizeof (struct mo_file_header)) + + fh = CreateFileA (filename, GENERIC_READ, FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + if (fh == INVALID_HANDLE_VALUE) + return NULL; + + size = GetFileSize (fh, NULL); + if (size == INVALID_FILE_SIZE) { - fclose (fp); + CloseHandle (fh); return NULL; } data = (2*size <= size)? NULL : jnlib_malloc (2*size); if (!data) { - fclose (fp); + CloseHandle (fh); return NULL; } @@ -1207,10 +1259,13 @@ load_domain (const char *filename) read_ptr = (char *) data; do { - long int nb = fread (read_ptr, 1, to_read, fp); - if (nb < to_read) + BOOL res; + DWORD nb; + + res = ReadFile (fh, read_ptr, to_read, &nb, NULL); + if (! res || nb < to_read) { - fclose (fp); + CloseHandle (fh); jnlib_free (data); return NULL; } @@ -1218,7 +1273,7 @@ load_domain (const char *filename) to_read -= nb; } while (to_read > 0); - fclose (fp); + CloseHandle (fh); /* Using the magic number we can test whether it really is a message catalog file. */ @@ -1238,7 +1293,7 @@ load_domain (const char *filename) domain->data = (char *) data; domain->data_native = (char *) data + size; domain->must_swap = data->magic != MAGIC; - + /* Fill in the information about the available tables. */ switch (SWAPIT (domain->must_swap, data->revision)) { @@ -1252,7 +1307,7 @@ load_domain (const char *filename) that many translations is very unlikely given that GnuPG with its very large number of strings has only about 1600 strings + variants. */ - nstrings = SWAPIT (domain->must_swap, data->nstrings); + nstrings = SWAPIT (domain->must_swap, data->nstrings); if (nstrings > 65534) goto bailout; domain->nstrings = nstrings; @@ -1298,7 +1353,7 @@ utf8_to_wchar (const char *string, size_t length, size_t *retlen) return NULL; nbytes = (size_t)(n+1) * sizeof(*result); - if (nbytes / sizeof(*result) != (n+1)) + if (nbytes / sizeof(*result) != (n+1)) { gpg_err_set_errno (ENOMEM); return NULL; @@ -1551,17 +1606,28 @@ get_string (struct loaded_domain *domain, uint32_t idx, + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); } - else if (!domain->mapped[idx]) + else if (!domain->mapped[idx]) { /* Not yet mapped. Map from utf-8 to native encoding now. */ const char *p_utf8; size_t plen_utf8, buflen; char *buf; - p_utf8 = (domain->data + p_utf8 = (domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); plen_utf8 = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); - + + /* We need to include the nul, so that the utf8->wchar->native + conversion chain works correctly and the nul is stored after + the conversion. */ + if (p_utf8[plen_utf8]) + { + trans = "ERROR in MO file"; /* Terminating zero is missing. */ + translen = 0; + goto leave; + } + plen_utf8++; + buf = utf8_to_native (p_utf8, plen_utf8, &buflen); if (!buf) { @@ -1573,7 +1639,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, /* Copy into the DATA_NATIVE area. */ char *p_tmp; - p_tmp = (domain->data_native + p_tmp = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); memcpy (p_tmp, buf, buflen); domain->mapped[idx] = buflen; @@ -1585,10 +1651,10 @@ get_string (struct loaded_domain *domain, uint32_t idx, /* There is not enough space for the translation (or for whatever reason an empty string is used): Store it in the overflow_space and mark that in the mapped array. - Because UTF-8 strings are in general shorter than the - Windows 2 byte encodings, we expect that this won't - happen too often (if at all) and thus we use a linked - list to manage this space. */ + Because UTF-8 strings are in general longer than the + Windows native encoding, we expect that this won't happen + too often and thus we use a linked list to manage this + space. */ os = jnlib_malloc (sizeof *os + buflen); if (os) { @@ -1607,9 +1673,11 @@ get_string (struct loaded_domain *domain, uint32_t idx, translen = 0; } } + if (translen) + translen--; /* TRANSLEN shall be the size without the nul. */ jnlib_free (buf); } - else if (domain->mapped[idx] == 1) + else if (domain->mapped[idx] == 1) { /* The translated string is in the overflow_space. */ for (os=domain->overflow_space; os; os = os->next) @@ -1626,13 +1694,14 @@ get_string (struct loaded_domain *domain, uint32_t idx, translen = 0; } } - else - { + else + { trans = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = domain->mapped[idx]; } + leave: if (use_plural && translen) return get_plural (trans, translen, nplural); else @@ -1641,7 +1710,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, static const char * -do_gettext (const char *domainname, +do_gettext (const char *domainname, const char *msgid, const char *msgid2, unsigned long nplural) { struct domainlist_s *dl; @@ -1649,14 +1718,14 @@ do_gettext (const char *domainname, int load_failed; uint32_t top, bottom, nstr; char *filename; - + if (!domainname) domainname = current_domainname? current_domainname : ""; /* FIXME: The whole locking stuff is a bit questionable because gettext does not claim to be thread-safe. We need to investigate this further. */ - + load_failed = 0; domain = NULL; filename = NULL; @@ -1708,7 +1777,7 @@ do_gettext (const char *domainname, domain = NULL; } } - + if (!domain) goto not_found; /* No MO file. */ @@ -1725,7 +1794,7 @@ do_gettext (const char *domainname, { nstr--; if (nstr < domain->nstrings - && SWAPIT(domain->must_swap, + && SWAPIT(domain->must_swap, domain->orig_tab[nstr].length) >= len && !strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1748,7 +1817,7 @@ do_gettext (const char *domainname, while (bottom < top) { int cmp_val; - + nstr = (bottom + top) / 2; cmp_val = strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1854,10 +1923,10 @@ _gpg_w32_gettext_use_utf8 (int value) int main (int argc, char **argv) { - const char atext1[] = + const char atext1[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u character long."; - const char atext2[] = + const char atext2[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u characters long."; @@ -1866,7 +1935,7 @@ main (int argc, char **argv) argc--; argv++; } - + _gpg_err_w32_bindtextdomain ("gnupg2", "c:/programme/gnu/gnupg/share/locale"); printf ("locale is `%s'\n", _gpg_err_w32_gettext_localename ()); -- cgit v1.2.3