Make libpq_gettext save and restore errno in a Windows-compatible way.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jul 2005 15:24:53 +0000 (15:24 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jul 2005 15:24:53 +0000 (15:24 +0000)
Also, back-patch fix into back branches.

src/interfaces/libpq/fe-misc.c

index 5de3360db9d0c5bb189235c19104b756e45ac3a5..94f620acd19887e61cc2a9da91985f49f5b6e626 100644 (file)
@@ -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);