Skip to content

Commit 4e9fa6d

Browse files
committed
Don't expose Windows' mbstowcs_l() and wcstombs_l().
Windows has similar functions with leading underscores. Previously, we provided the rename via a macro in win32_port.h. In fact its functions are not always good replacements for the Unix functions, since they can't deal with UTF-8. They are only currently used by pg_locale.c, which is careful to redirect to other Windows routines for UTF-8. Given that portability hazard, it seem unlikely to be a good idea to encourage any other code to think of these functions as being available outside pg_locale.c. Any code that thinks it wants these functions probably wants our wchar2char() or char2wchar() routines instead, or it won't actually work on Windows in UTF-8 databases. Furthermore, some major libc implementations including glibc don't have them (they only have the standard variants without _l), so external code is very unlikely to require them to exist. Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/CA%2BhUKG%2Bt_CHPzEoPnKyARJBJgE9-GxNajJo6ZuSfRK_KWFO%2B6w%40mail.gmail.com
1 parent a8b7424 commit 4e9fa6d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,36 +154,41 @@ static void icu_set_collation_attributes(UCollator *collator, const char *loc,
154154
UErrorCode *status);
155155
#endif
156156

157-
#ifndef WIN32
158157
/*
159158
* POSIX doesn't define _l-variants of these functions, but several systems
160-
* have them. We provide our own replacements here. For Windows, we have
161-
* macros in win32_port.h.
159+
* have them. We provide our own replacements here.
162160
*/
163161
#ifndef HAVE_MBSTOWCS_L
164162
static size_t
165163
mbstowcs_l(wchar_t *dest, const char *src, size_t n, locale_t loc)
166164
{
165+
#ifdef WIN32
166+
return _mbstowcs_l(dest, src, n, loc);
167+
#else
167168
size_t result;
168169
locale_t save_locale = uselocale(loc);
169170

170171
result = mbstowcs(dest, src, n);
171172
uselocale(save_locale);
172173
return result;
174+
#endif
173175
}
174176
#endif
175177
#ifndef HAVE_WCSTOMBS_L
176178
static size_t
177179
wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)
178180
{
181+
#ifdef WIN32
182+
return _wcstombs_l(dest, src, n, loc);
183+
#else
179184
size_t result;
180185
locale_t save_locale = uselocale(loc);
181186

182187
result = wcstombs(dest, src, n);
183188
uselocale(save_locale);
184189
return result;
185-
}
186190
#endif
191+
}
187192
#endif
188193

189194
/*

src/include/port/win32_port.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,6 @@ extern int _pglstat64(const char *name, struct stat *buf);
455455
#define strcoll_l _strcoll_l
456456
#define strxfrm_l _strxfrm_l
457457
#define wcscoll_l _wcscoll_l
458-
#define wcstombs_l _wcstombs_l
459-
#define mbstowcs_l _mbstowcs_l
460458

461459
/*
462460
* Versions of libintl >= 0.18? try to replace setlocale() with a macro

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy