aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-09-23 09:20:39 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-09-23 09:20:39 +0000
commit61d967498802ab86d8897cb3c61740d7e9d712f6 (patch)
tree5571f2188fbc53d5d987bfc9c45036c83355de11 /src/backend/utils/adt/pg_locale.c
parentc52aab5525c13a3d378cd09f4187844ce697a948 (diff)
downloadpostgresql-61d967498802ab86d8897cb3c61740d7e9d712f6.tar.gz
postgresql-61d967498802ab86d8897cb3c61740d7e9d712f6.zip
Make LC_COLLATE and LC_CTYPE database-level settings. Collation and
ctype are now more like encoding, stored in new datcollate and datctype columns in pg_database. This is a stripped-down version of Radek Strnad's patch, with further changes by me.
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index dfc6c886a52..4b57d5791e0 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-2008, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.41 2008/05/19 18:08:16 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.42 2008/09/23 09:20:36 heikki Exp $
*
*-----------------------------------------------------------------------
*/
@@ -76,7 +76,7 @@ static bool CurrentLCTimeValid = false;
/* Environment variable storage area */
-#define LC_ENV_BUFSIZE (LOCALE_NAME_BUFLEN + 20)
+#define LC_ENV_BUFSIZE (NAMEDATALEN + 20)
static char lc_collate_envbuf[LC_ENV_BUFSIZE];
static char lc_ctype_envbuf[LC_ENV_BUFSIZE];
@@ -189,6 +189,31 @@ pg_perm_setlocale(int category, const char *locale)
}
+/*
+ * Is the locale name valid for the locale category?
+ */
+bool
+check_locale(int category, const char *value)
+{
+ char *save;
+ bool ret;
+
+ save = setlocale(category, NULL);
+ if (!save)
+ return false; /* won't happen, we hope */
+
+ /* save may be pointing at a modifiable scratch variable, see above */
+ save = pstrdup(save);
+
+ /* set the locale with setlocale, to see if it accepts it. */
+ ret = (setlocale(category, value) != NULL);
+
+ setlocale(category, save); /* assume this won't fail */
+ pfree(save);
+
+ return ret;
+}
+
/* GUC assign hooks */
/*
@@ -203,21 +228,9 @@ pg_perm_setlocale(int category, const char *locale)
static const char *
locale_xxx_assign(int category, const char *value, bool doit, GucSource source)
{
- char *save;
-
- save = setlocale(category, NULL);
- if (!save)
- return NULL; /* won't happen, we hope */
-
- /* save may be pointing at a modifiable scratch variable, see above */
- save = pstrdup(save);
-
- if (!setlocale(category, value))
+ if (!check_locale(category, value))
value = NULL; /* set failure return marker */
- setlocale(category, save); /* assume this won't fail */
- pfree(save);
-
/* need to reload cache next time? */
if (doit && value != NULL)
{