summaryrefslogtreecommitdiffstats
path: root/gl/mbtowc-lock.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/mbtowc-lock.h')
-rw-r--r--gl/mbtowc-lock.h17
1 files changed, 7 insertions, 10 deletions
diff --git a/gl/mbtowc-lock.h b/gl/mbtowc-lock.h
index 500f74cc..b3e4e28e 100644
--- a/gl/mbtowc-lock.h
+++ b/gl/mbtowc-lock.h
@@ -1,5 +1,5 @@
1/* Use the internal lock used by mbrtowc and mbrtoc32. 1/* Use the internal lock used by mbrtowc and mbrtoc32.
2 Copyright (C) 2019-2025 Free Software Foundation, Inc. 2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 3
4 This file is free software: you can redistribute it and/or modify 4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as 5 it under the terms of the GNU Lesser General Public License as
@@ -23,7 +23,7 @@ mbtowc_unlocked (wchar_t *pwc, const char *p, size_t m)
23{ 23{
24 /* Put the hidden internal state of mbtowc into an initial state. 24 /* Put the hidden internal state of mbtowc into an initial state.
25 This is needed at least with glibc, uClibc, and MSVC CRT. 25 This is needed at least with glibc, uClibc, and MSVC CRT.
26 See <https://sourceware.org/bugzilla/show_bug.cgi?id=9674>. */ 26 See <https://sourceware.org/PR9674>. */
27 mbtowc (NULL, NULL, 0); 27 mbtowc (NULL, NULL, 0);
28 28
29 return mbtowc (pwc, p, m); 29 return mbtowc (pwc, p, m);
@@ -50,16 +50,15 @@ static int
50mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m) 50mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
51{ 51{
52 CRITICAL_SECTION *lock = gl_get_mbtowc_lock (); 52 CRITICAL_SECTION *lock = gl_get_mbtowc_lock ();
53 int ret;
54 53
55 EnterCriticalSection (lock); 54 EnterCriticalSection (lock);
56 ret = mbtowc_unlocked (pwc, p, m); 55 int ret = mbtowc_unlocked (pwc, p, m);
57 LeaveCriticalSection (lock); 56 LeaveCriticalSection (lock);
58 57
59 return ret; 58 return ret;
60} 59}
61 60
62#elif HAVE_PTHREAD_API /* AIX, IRIX, Cygwin */ 61#elif HAVE_PTHREAD_API /* AIX, Cygwin */
63 62
64extern 63extern
65# if defined _WIN32 || defined __CYGWIN__ 64# if defined _WIN32 || defined __CYGWIN__
@@ -67,7 +66,7 @@ extern
67# endif 66# endif
68 pthread_mutex_t *gl_get_mbtowc_lock (void); 67 pthread_mutex_t *gl_get_mbtowc_lock (void);
69 68
70# if HAVE_WEAK_SYMBOLS /* IRIX */ 69# if HAVE_WEAK_SYMBOLS
71 70
72 /* Avoid the need to link with '-lpthread'. */ 71 /* Avoid the need to link with '-lpthread'. */
73# pragma weak pthread_mutex_lock 72# pragma weak pthread_mutex_lock
@@ -89,11 +88,10 @@ mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
89 if (pthread_in_use()) 88 if (pthread_in_use())
90 { 89 {
91 pthread_mutex_t *lock = gl_get_mbtowc_lock (); 90 pthread_mutex_t *lock = gl_get_mbtowc_lock ();
92 int ret;
93 91
94 if (pthread_mutex_lock (lock)) 92 if (pthread_mutex_lock (lock))
95 abort (); 93 abort ();
96 ret = mbtowc_unlocked (pwc, p, m); 94 int ret = mbtowc_unlocked (pwc, p, m);
97 if (pthread_mutex_unlock (lock)) 95 if (pthread_mutex_unlock (lock))
98 abort (); 96 abort ();
99 97
@@ -111,11 +109,10 @@ static int
111mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m) 109mbtowc_with_lock (wchar_t *pwc, const char *p, size_t m)
112{ 110{
113 mtx_t *lock = gl_get_mbtowc_lock (); 111 mtx_t *lock = gl_get_mbtowc_lock ();
114 int ret;
115 112
116 if (mtx_lock (lock) != thrd_success) 113 if (mtx_lock (lock) != thrd_success)
117 abort (); 114 abort ();
118 ret = mbtowc_unlocked (pwc, p, m); 115 int ret = mbtowc_unlocked (pwc, p, m);
119 if (mtx_unlock (lock) != thrd_success) 116 if (mtx_unlock (lock) != thrd_success)
120 abort (); 117 abort ();
121 118