Fix failure to copy setlocale() return value.
Fix failure to copy setlocale() return value.

POSIX permits setlocale() calls to invalidate any previous setlocale()
return values, but commit 5f538ad004aa00cf0881f179f0cde789aad4f47e
neglected to account for setlocale(LC_CTYPE, NULL) doing so.  The effect
was to set the LC_CTYPE environment variable to an unintended value.
pg_perm_setlocale() sets this variable to assist PL/Perl; without it,
Perl would undo PostgreSQL's locale settings.  The known-affected
configurations are 32-bit, release builds using Visual Studio 2012 or
Visual Studio 2013.  Visual Studio 2010 is unaffected, as were all
buildfarm-attested configurations.  In principle, this bug could leave
the wrong LC_CTYPE in effect after PL/Perl use, which could in turn
facilitate problems like corrupt tsvector datums.  No known platform
experiences that consequence, because PL/Perl on Windows does not use
this environment variable.

The bug has been user-visible, as early postmaster failure, on systems
with Windows ANSI code page set to CP936 for "Chinese (Simplified, PRC)"
and probably on systems using other multibyte code pages.
(SetEnvironmentVariable() rejects values containing character data not
valid under the Windows ANSI code page.)  Back-patch to 9.4, where the
faulty commit first appeared.

Reported by Didi Hu and 林鹏程.  Reviewed by Tom Lane, though this fix
strategy was not his first choice.

greenplum-db/gpdb,ashwinstar/gpdb,Postgres-XL/Postgres-XL,ashwinstar/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,lisakowen/gpdb,50wu/gpdb,50wu/gpdb,Postgres-XL/Postgres-XL,ovr/postgres-xl,oberstet/postgres-xl,Postgres-XL/Postgres-XL,lisakowen/gpdb,zeroae/postgres-xl,techdragon/Postgres-XL,yazun/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,adam8157/gpdb,greenplum-db/gpdb,oberstet/postgres-xl,ovr/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,lisakowen/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,50wu/gpdb,lisakowen/gpdb,lisakowen/gpdb,xinzweb/gpdb,zeroae/postgres-xl,zeroae/postgres-xl,pavanvd/postgres-xl,xinzweb/gpdb,oberstet/postgres-xl,yazun/postgres-xl,xinzweb/gpdb,Postgres-XL/Postgres-XL,lisakowen/gpdb,ovr/postgres-xl,zeroae/postgres-xl,adam8157/gpdb,greenplum-db/gpdb,50wu/gpdb,jmcatamney/gpdb,adam8157/gpdb,yazun/postgres-xl,adam8157/gpdb,jmcatamney/gpdb,xinzweb/gpdb,jmcatamney/gpdb,xinzweb/gpdb,zeroae/postgres-xl,ashwinstar/gpdb,yazun/postgres-xl,pavanvd/postgres-xl,jmcatamney/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xinzweb/gpdb,50wu/gpdb,pavanvd/postgres-xl,pavanvd/postgres-xl,techdragon/Postgres-XL,pavanvd/postgres-xl,ovr/postgres-xl,oberstet/postgres-xl,yazun/postgres-xl,lisakowen/gpdb,lisakowen/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,adam8157/gpdb,ovr/postgres-xl,ashwinstar/gpdb,techdragon/Postgres-XL,greenplum-db/gpdb,50wu/gpdb,adam8157/gpdb,ashwinstar/gpdb,Postgres-XL/Postgres-XL,techdragon/Postgres-XL,ashwinstar/gpdb,xinzweb/gpdb,techdragon/Postgres-XL,50wu/gpdb,xinzweb/gpdb,oberstet/postgres-xl,50wu/gpdb