aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-07-08 15:24:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-07-08 15:24:53 +0000
commita646e4874a1e792a3261a8087833e04b9715ac1d (patch)
treeb5ace27c916cb255b68c513726085facc46b0e43 /src/interfaces/libpq/fe-misc.c
parent75aed9f0c262bd930de01fed29381e281b35588c (diff)
downloadpostgresql-a646e4874a1e792a3261a8087833e04b9715ac1d.tar.gz
postgresql-a646e4874a1e792a3261a8087833e04b9715ac1d.zip
Make libpq_gettext save and restore errno in a Windows-compatible way.
Also, back-patch fix into back branches.
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index f3691c783b5..3571af7b911 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -23,7 +23,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.112 2004/12/31 22:03:50 pgsql Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.112.4.1 2005/07/08 15:24:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1127,13 +1127,25 @@ PQenv2encoding(void)
char *
libpq_gettext(const char *msgid)
{
- static int already_bound = 0;
+ static bool already_bound = false;
if (!already_bound)
{
- already_bound = 1;
+ /* dgettext() preserves errno, but bindtextdomain() doesn't */
+ int save_errno = errno;
+ const char *ldir;
+
+ already_bound = true;
/* No relocatable lookup here because the binary could be anywhere */
- bindtextdomain("libpq", getenv("PGLOCALEDIR") ? getenv("PGLOCALEDIR") : LOCALEDIR);
+ ldir = getenv("PGLOCALEDIR");
+ if (!ldir)
+ ldir = LOCALEDIR;
+ bindtextdomain("libpq", ldir);
+#ifdef WIN32
+ SetLastError(save_errno);
+#else
+ errno = save_errno;
+#endif
}
return dgettext("libpq", msgid);