aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2005-03-16 00:03:02 +0000
committerBruce Momjian <bruce@momjian.us>2005-03-16 00:03:02 +0000
commitfb2c2d83e0a53d79eed032b51049a87908731257 (patch)
tree332f6dfca511a87e636f19c4e9bb3317e28a6585 /src/backend/utils/adt/pg_locale.c
parentf38cb720d9435ade289c559d2082877d4ebbf4cc (diff)
downloadpostgresql-fb2c2d83e0a53d79eed032b51049a87908731257.tar.gz
postgresql-fb2c2d83e0a53d79eed032b51049a87908731257.zip
Prevent locale-aware handling of upper, lower, and initcap when the
locale is C. Backpatch to 8.0.X because some operating systems were throwing errors for such operations, rather than ignoring the locale when it was C.
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 5b8d8e88102..f2d5f2c5cef 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -4,7 +4,7 @@
*
* Portions Copyright (c) 2002-2005, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.30 2005/01/01 05:43:07 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.30.4.1 2005/03/16 00:03:02 momjian Exp $
*
*-----------------------------------------------------------------------
*/
@@ -197,6 +197,33 @@ lc_collate_is_c(void)
/*
+ * We'd like to cache whether LC_CTYPE is C (or POSIX), so we can
+ * optimize a few code paths in various places.
+ */
+bool
+lc_ctype_is_c(void)
+{
+ /* Cache result so we only have to compute it once */
+ static int result = -1;
+ char *localeptr;
+
+ if (result >= 0)
+ return (bool) result;
+ localeptr = setlocale(LC_CTYPE, NULL);
+ if (!localeptr)
+ elog(ERROR, "invalid LC_CTYPE setting");
+
+ if (strcmp(localeptr, "C") == 0)
+ result = true;
+ else if (strcmp(localeptr, "POSIX") == 0)
+ result = true;
+ else
+ result = false;
+ return (bool) result;
+}
+
+
+/*
* Frees the malloced content of a struct lconv. (But not the struct
* itself.)
*/