]> granicus.if.org Git - postgresql/commitdiff
Add port support for unsetenv() in back branches. Needed for locale
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 5 Jan 2006 00:51:52 +0000 (00:51 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 5 Jan 2006 00:51:52 +0000 (00:51 +0000)
environment fix.

configure
configure.in
src/include/c.h
src/include/pg_config.h.in
src/port/unsetenv.c [new file with mode: 0644]

index c1ed341f3fee9b6d6326a82c508b854e4ad0913a..1ea56f8074c0cb9bc162d300b4f842fda5443642 100755 (executable)
--- a/configure
+++ b/configure
@@ -10531,7 +10531,8 @@ fi
 
 
 
-for ac_func in fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
+
+for ac_func in fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul unsetenv
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -11168,7 +11169,8 @@ echo "${ECHO_T}$ac_cv_header_syslog_h" >&6
 
 fi
 if test $ac_cv_header_syslog_h = yes; then
-  cat >>confdefs.h <<\_ACEOF
+
+cat >>confdefs.h <<\_ACEOF
 #define HAVE_SYSLOG 1
 _ACEOF
 
index 1bed6951572702c6e262aed6324a6b1d8aa956b2..8136f2fd2a03bb9ea04d653418ddd7c89a895b1d 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.217.2.19 2005/12/09 20:56:45 tgl Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.217.2.20 2006/01/05 00:51:52 tgl Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -840,7 +840,7 @@ else
   AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
 fi
 
-AC_REPLACE_FUNCS([fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
+AC_REPLACE_FUNCS([fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul unsetenv])
 
 # BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
 # We override the previous test that said fseeko/ftello didn't exist
@@ -895,7 +895,7 @@ AC_MSG_RESULT(yes)],
 
 AC_CHECK_FUNC(syslog, 
             [AC_CHECK_HEADER(syslog.h,
-            [AC_DEFINE(HAVE_SYSLOG, 1, [])],
+            [AC_DEFINE(HAVE_SYSLOG, 1, [Define to 1 if you have the syslog interface.])],
             [])])
 
 AC_CACHE_CHECK([for optreset], pgac_cv_var_int_optreset,
index 9c67797cd9af18e4877ba2b2c4da140bfd86105f..f8e145ea96c680e4ff06936c59802778070f9418 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: c.h,v 1.130.2.1 2005/07/18 15:54:30 tgl Exp $
+ * $Id: c.h,v 1.130.2.2 2006/01/05 00:51:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -669,4 +669,8 @@ extern int  vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 #define memmove(d, s, c)               bcopy(s, d, c)
 #endif
 
+#ifndef HAVE_UNSETENV
+extern void unsetenv(const char *name);
+#endif
+
 #endif   /* C_H */
index fd8488e20c0aa9d51597f5611dde202a48f35d89..33c960e5f59d4ae4a1abf1191fe6c1c18b8b5613 100644 (file)
@@ -8,7 +8,7 @@
  * or in pg_config.h afterwards.  Of course, if you edit pg_config.h, then your
  * changes will be overwritten the next time you run configure.
  *
- * $Id: pg_config.h.in,v 1.32.2.1 2002/11/08 05:23:09 tgl Exp $
+ * $Id: pg_config.h.in,v 1.32.2.2 2006/01/05 00:51:52 tgl Exp $
  */
 
 #ifndef PG_CONFIG_H
 /* Set to 1 if you have isinf() */
 #undef HAVE_ISINF
 
+/* Define to 1 if you have the `unsetenv' function. */
+#undef HAVE_UNSETENV
+
 /*
  *     These are all related to port/isinf.c 
  */
diff --git a/src/port/unsetenv.c b/src/port/unsetenv.c
new file mode 100644 (file)
index 0000000..09e14f2
--- /dev/null
@@ -0,0 +1,56 @@
+/*-------------------------------------------------------------------------
+ *
+ * unsetenv.c
+ *       unsetenv() emulation for machines without it
+ *
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *       $PostgreSQL: pgsql/src/port/unsetenv.c,v 1.6.4.1 2006/01/05 00:51:52 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "c.h"
+
+
+void
+unsetenv(const char *name)
+{
+       char       *envstr;
+
+       if (getenv(name) == NULL)
+               return;                                 /* no work */
+
+       /*
+        * The technique embodied here works if libc follows the Single Unix Spec
+        * and actually uses the storage passed to putenv() to hold the environ
+        * entry.  When we clobber the entry in the second step we are ensuring
+        * that we zap the actual environ member.  However, there are some libc
+        * implementations (notably recent BSDs) that do not obey SUS but copy the
+        * presented string.  This method fails on such platforms.      Hopefully all
+        * such platforms have unsetenv() and thus won't be using this hack.
+        *
+        * Note that repeatedly setting and unsetting a var using this code will
+        * leak memory.
+        */
+
+       envstr = (char *) malloc(strlen(name) + 2);
+       if (!envstr)                            /* not much we can do if no memory */
+               return;
+
+       /* Override the existing setting by forcibly defining the var */
+       sprintf(envstr, "%s=", name);
+       putenv(envstr);
+
+       /* Now we can clobber the variable definition this way: */
+       strcpy(envstr, "=");
+
+       /*
+        * This last putenv cleans up if we have multiple zero-length names as a
+        * result of unsetting multiple things.
+        */
+       putenv(envstr);
+}