diff options
author | Werner Koch <wk@gnupg.org> | 2018-12-07 14:46:25 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2018-12-07 14:50:05 +0100 |
commit | 0b190ce89de7b3df873c3896d5126c7882b82e18 (patch) | |
tree | f1721d4dd91fa1929c817fa14d53d89875af325c /src/w32-gettext.c | |
parent | 9e62d5e73f30c1386de5153c93fd169889e9e66d (diff) | |
download | libgpg-error-0b190ce89de7b3df873c3896d5126c7882b82e18.tar.gz |
Add W32-only function gpgrt_w32_override_locale.
* src/w32-gettext.c (struct override_locale): new.
(my_nl_locale_name): Take care of that.
(gpgrt_w32_override_locale): New.
* src/gpg-error.def.in: Add gpgrt_w32_override_locale.
* src/gpg-error.c: New command --locale for Windows.
--
GnuPG-bug-id: 3733
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/w32-gettext.c')
-rw-r--r-- | src/w32-gettext.c | 73 |
1 files changed, 55 insertions, 18 deletions
diff --git a/src/w32-gettext.c b/src/w32-gettext.c index 3b54ebd..11e4f3d 100644 --- a/src/w32-gettext.c +++ b/src/w32-gettext.c @@ -53,6 +53,16 @@ #include "init.h" #include "gpg-error.h" +/* Override values initialized by gpgrt_w32_override_locale. If NAME + * is not the empty string LANGID will be used. */ +static struct +{ + unsigned short active; /* If not zero this override is active. */ + unsigned short langid; + char name[28]; +} override_locale; + + #ifdef HAVE_W32CE_SYSTEM /* Forward declaration. */ static wchar_t *utf8_to_wchar (const char *string, size_t length, size_t *retlen); @@ -647,33 +657,42 @@ my_nl_locale_name (const char *categoryname) #ifndef HAVE_W32CE_SYSTEM const char *retval; #endif - LCID lcid; LANGID langid; int primary, sub; - /* Let the user override the system settings through environment - variables, as on POSIX systems. */ + if (override_locale.active) + { + if (*override_locale.name) + return override_locale.name; + langid = override_locale.langid; + } + else + { + LCID lcid; + + /* Let the user override the system settings through environment + * variables, as on POSIX systems. */ #ifndef HAVE_W32CE_SYSTEM - retval = getenv ("LC_ALL"); - if (retval != NULL && retval[0] != '\0') - return retval; - retval = getenv (categoryname); - if (retval != NULL && retval[0] != '\0') - return retval; - retval = getenv ("LANG"); - if (retval != NULL && retval[0] != '\0') - return retval; + retval = getenv ("LC_ALL"); + if (retval != NULL && retval[0] != '\0') + return retval; + retval = getenv (categoryname); + if (retval != NULL && retval[0] != '\0') + return retval; + retval = getenv ("LANG"); + if (retval != NULL && retval[0] != '\0') + return retval; #endif /*!HAVE_W32CE_SYSTEM*/ - /* Use native Win32 API locale ID. */ + /* Use native Win32 API locale ID. */ #ifdef HAVE_W32CE_SYSTEM - lcid = GetSystemDefaultLCID (); + lcid = GetSystemDefaultLCID (); #else - lcid = GetThreadLocale (); + lcid = GetThreadLocale (); #endif - - /* Strip off the sorting rules, keep only the language part. */ - langid = LANGIDFROMLCID (lcid); + /* Strip off the sorting rules, keep only the language part. */ + langid = LANGIDFROMLCID (lcid); + } /* Split into language and territory part. */ primary = PRIMARYLANGID (langid); @@ -1922,6 +1941,24 @@ _gpg_w32_gettext_use_utf8 (int value) } +/* Force the use of the locale NAME or if NAME is NULL the locale + * derived from LANGID will be used. This function is not thread-safe + * and must be used early - even before gpgrt_check_version. */ +void +gpgrt_w32_override_locale (const char *name, unsigned short langid) +{ + if (name) + { + strncpy (override_locale.name, name, sizeof (override_locale.name) - 1); + override_locale.name[sizeof (override_locale.name) - 1] = 0; + } + else + *override_locale.name = 0; + override_locale.langid = langid; + override_locale.active = 1; +} + + #ifdef TEST int main (int argc, char **argv) |