Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1f32999

Browse files
committed
On OS X, assume that an empty-string result for nl_langinfo(CODESET)
means UTF-8. Per examination of /usr/share/locale in 10.4.10.
1 parent 304750f commit 1f32999

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/port/chklocale.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/chklocale.c,v 1.1 2007/09/28 22:25:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/port/chklocale.c,v 1.2 2007/09/28 23:36:06 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -158,6 +158,7 @@ pg_get_encoding_from_locale(const char *ctype)
158158
char *sys;
159159
int i;
160160

161+
/* Get the CODESET property, and also LC_CTYPE if not passed in */
161162
if (ctype)
162163
{
163164
char *save;
@@ -197,12 +198,14 @@ pg_get_encoding_from_locale(const char *ctype)
197198
if (!sys)
198199
return PG_SQL_ASCII; /* out of memory; unlikely */
199200

201+
/* If locale is C or POSIX, we can allow all encodings */
200202
if (pg_strcasecmp(ctype, "C") == 0 || pg_strcasecmp(ctype, "POSIX") == 0)
201203
{
202204
free(sys);
203205
return PG_SQL_ASCII;
204206
}
205207

208+
/* Check the table */
206209
for (i = 0; encoding_match_list[i].system_enc_name; i++)
207210
{
208211
if (pg_strcasecmp(sys, encoding_match_list[i].system_enc_name) == 0)
@@ -212,6 +215,20 @@ pg_get_encoding_from_locale(const char *ctype)
212215
}
213216
}
214217

218+
/* Special-case kluges for particular platforms go here */
219+
220+
#ifdef __darwin__
221+
/*
222+
* Current OS X has many locales that report an empty string for CODESET,
223+
* but they all seem to actually use UTF-8.
224+
*/
225+
if (strlen(sys) == 0)
226+
{
227+
free(sys);
228+
return PG_UTF8;
229+
}
230+
#endif
231+
215232
/*
216233
* We print a warning if we got a CODESET string but couldn't recognize
217234
* it. This means we need another entry in the table.

0 commit comments

Comments
 (0)