aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2024-08-02 07:42:57 +0000
committerWerner Koch <[email protected]>2024-08-02 07:42:57 +0000
commit7f36440d90964ffe809064365cb16033ba1dda69 (patch)
tree81484b41aa661c378560c6606d19a420e8438d52 /src
parentUpdate version date of autogen.sh (diff)
downloadlibgpg-error-7f36440d90964ffe809064365cb16033ba1dda69.tar.gz
libgpg-error-7f36440d90964ffe809064365cb16033ba1dda69.zip
w32: Allow initialization of new threads to utf8 mode.
* src/init.c (utf8_for_new_threads): New var. (_gpgrt_w32_utf8_for_new_threads): New func. (get_tls): Init the TLS utf8 flag from the new var. * src/w32-gettext.c (_gpg_w32_gettext_use_utf8): Implement new flag. -- GnuPG-bug-id: 7185
Diffstat (limited to 'src')
-rw-r--r--src/init.c14
-rw-r--r--src/init.h7
-rw-r--r--src/w32-add.h7
-rw-r--r--src/w32-gettext.c16
4 files changed, 35 insertions, 9 deletions
diff --git a/src/init.c b/src/init.c
index c4b7e56..8a5e651 100644
--- a/src/init.c
+++ b/src/init.c
@@ -39,6 +39,8 @@
static int tls_index = TLS_OUT_OF_INDEXES; /* Index for the TLS functions. */
+static volatile int utf8_for_new_threads;
+
static char *get_locale_dir (void);
static void drop_locale_dir (char *locale_dir);
@@ -549,6 +551,14 @@ _gpgrt_internal_trace_end (void)
******** Below is only Windows code. ****
*****************************************/
+/* This function can be called to force utf8 for new threads. */
+void
+_gpgrt_w32_utf8_for_new_threads (void)
+{
+ utf8_for_new_threads = 1;
+}
+
+
static char *
get_locale_dir (void)
{
@@ -645,7 +655,7 @@ get_tls (void)
/* No way to continue - commit suicide. */
_gpgrt_abort ();
}
- tls->gt_use_utf8 = 0;
+ tls->gt_use_utf8 = utf8_for_new_threads;
TlsSetValue (tls_index, tls);
}
@@ -677,7 +687,7 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)
tls = LocalAlloc (LPTR, sizeof *tls);
if (!tls)
return FALSE;
- tls->gt_use_utf8 = 0;
+ tls->gt_use_utf8 = utf8_for_new_threads;
TlsSetValue (tls_index, tls);
if (reason == DLL_PROCESS_ATTACH)
{
diff --git a/src/init.h b/src/init.h
index ea7154d..269e2c2 100644
--- a/src/init.h
+++ b/src/init.h
@@ -7,12 +7,12 @@
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 <https://www.gnu.org/licenses/>.
*/
@@ -47,6 +47,9 @@ struct tls_space_s
int gt_use_utf8;
};
+/* Force UTF8 for new threads. */
+void _gpgrt_w32_utf8_for_new_threads (void);
+
/* Return the TLS. */
struct tls_space_s *get_tls (void);
diff --git a/src/w32-add.h b/src/w32-add.h
index 74696bd..d567799 100644
--- a/src/w32-add.h
+++ b/src/w32-add.h
@@ -24,6 +24,13 @@ const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1,
const char *msgid2, unsigned long int n)
_GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3);
const char *_gpg_w32_gettext_localename (void);
+
+/* With a VALUE of 1 switch the gettext functions into utf8 mode; with
+ * 2 or 3 all new threads will initially be using UTF8 (this new
+ * default init can't be reverted, though). That is the strings are
+ * returned without translation to the native charset. A VALUE of 0
+ * switches back to translated strings. A VALUE of -1 returns the
+ * current value (1 or 0). */
int _gpg_w32_gettext_use_utf8 (int value);
#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS
diff --git a/src/w32-gettext.c b/src/w32-gettext.c
index 817c1ca..5b15a77 100644
--- a/src/w32-gettext.c
+++ b/src/w32-gettext.c
@@ -1947,17 +1947,23 @@ _gpg_w32_gettext_localename (void)
}
-/* With a VALUE of 1 switch the gettext functions into utf8 mode.
- That is the strings are returned without translation to the native
- charset. A VALUE of 0 switches back to translated strings. A VALUE
- of -1 returns the current value. */
+/* With a VALUE of 1 switch the gettext functions into utf8 mode; with
+ * 2 or 3 all new threads will initially be using UTF8. That is the
+ * strings are returned without translation to the native charset. A
+ * VALUE of 0 switches back to translated strings. A VALUE of -1
+ * returns the current value. */
int
_gpg_w32_gettext_use_utf8 (int value)
{
struct tls_space_s *tls = get_tls ();
int last = tls->gt_use_utf8;
if (value != -1)
- tls->gt_use_utf8 = value;
+ {
+ tls->gt_use_utf8 = !!value;
+
+ if ((value & 2))
+ _gpgrt_w32_utf8_for_new_threads ();
+ }
return last;
}