Commit 514f6132 authored by Tom Lane's avatar Tom Lane

Second try at getting useful errors out of newlocale/_create_locale.

The early buildfarm returns for commit 1e165d05 are pretty awful:
not only does Windows not return a useful error, but it looks like
a lot of Unix-ish platforms don't either.  Given the number of
different errnos seen so far, guess that what's really going on is
that some newlocale() implementations fail to set errno at all.
Hence, let's try zeroing errno just before newlocale() and then
if it's still zero report as though it's ENOENT.  That should cover
the Windows case too.

It's clear that we'll have to drop the regression test case, unless
we want to maintain a separate expected-file for platforms without
HAVE_LOCALE_T.  But I'll leave it there awhile longer to see if this
actually improves matters or not.

Discussion: https://postgr.es/m/CAKKotZS-wcDcofXDCH=sidiuajE+nqHn2CGjLLX78anyDmi3gQ@mail.gmail.com
parent 8e753726
...@@ -1229,10 +1229,15 @@ report_newlocale_failure(const char *localename) ...@@ -1229,10 +1229,15 @@ report_newlocale_failure(const char *localename)
{ {
int save_errno; int save_errno;
/* On Windows, transform _create_locale() error to errno */ /*
#ifdef WIN32 * Windows doesn't provide any useful error indication from
_dosmaperr(GetLastError()); * _create_locale(), and BSD-derived platforms don't seem to feel they
#endif * need to set errno either (even though POSIX is pretty clear that
* newlocale should do so). So, if errno hasn't been set, assume ENOENT
* is what to report.
*/
if (errno == 0)
errno = ENOENT;
/* /*
* ENOENT means "no such locale", not "no such file", so clarify that * ENOENT means "no such locale", not "no such file", so clarify that
...@@ -1311,6 +1316,7 @@ pg_newlocale_from_collation(Oid collid) ...@@ -1311,6 +1316,7 @@ pg_newlocale_from_collation(Oid collid)
if (strcmp(collcollate, collctype) == 0) if (strcmp(collcollate, collctype) == 0)
{ {
/* Normal case where they're the same */ /* Normal case where they're the same */
errno = 0;
#ifndef WIN32 #ifndef WIN32
loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collcollate, loc = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collcollate,
NULL); NULL);
...@@ -1326,9 +1332,11 @@ pg_newlocale_from_collation(Oid collid) ...@@ -1326,9 +1332,11 @@ pg_newlocale_from_collation(Oid collid)
/* We need two newlocale() steps */ /* We need two newlocale() steps */
locale_t loc1; locale_t loc1;
errno = 0;
loc1 = newlocale(LC_COLLATE_MASK, collcollate, NULL); loc1 = newlocale(LC_COLLATE_MASK, collcollate, NULL);
if (!loc1) if (!loc1)
report_newlocale_failure(collcollate); report_newlocale_failure(collcollate);
errno = 0;
loc = newlocale(LC_CTYPE_MASK, collctype, loc1); loc = newlocale(LC_CTYPE_MASK, collctype, loc1);
if (!loc) if (!loc)
report_newlocale_failure(collctype); report_newlocale_failure(collctype);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment