From 2ab0796d7a3a7116a79b65531fd33f1548514b52 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 23 Apr 2011 12:35:41 -0400 Subject: Fix char2wchar/wchar2char to support collations properly. These functions should take a pg_locale_t, not a collation OID, and should call mbstowcs_l/wcstombs_l where available. Where those functions are not available, temporarily select the correct locale with uselocale(). This change removes the bogus assumption that all locales selectable in a given database have the same wide-character conversion method; in particular, the collate.linux.utf8 regression test now passes with LC_CTYPE=C, so long as the database encoding is UTF8. I decided to move the char2wchar/wchar2char functions out of mbutils.c and into pg_locale.c, because they work on wchar_t not pg_wchar_t and thus don't really belong with the mbutils.c functions. Keeping them where they were would have required importing pg_locale_t into pg_wchar.h somehow, which did not seem like a good plan. --- src/include/utils/pg_locale.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/include/utils') diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index 25b9d50915..c59a004fc9 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -72,4 +72,12 @@ typedef int pg_locale_t; extern pg_locale_t pg_newlocale_from_collation(Oid collid); +/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */ +#ifdef USE_WIDE_UPPER_LOWER +extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen, + pg_locale_t locale); +extern size_t char2wchar(wchar_t *to, size_t tolen, + const char *from, size_t fromlen, pg_locale_t locale); +#endif + #endif /* _PG_LOCALE_ */ -- cgit v1.2.3