mirror of
https://github.com/postgres/postgres.git
synced 2025-05-17 06:41:24 +03:00
Add port support for unsetenv() in back branches. Needed for locale
environment fix.
This commit is contained in:
parent
fcacfc96a2
commit
37cdf43eaa
3
configure
vendored
3
configure
vendored
@ -11970,7 +11970,8 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
|
|
||||||
|
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv
|
||||||
do
|
do
|
||||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
echo "$as_me:$LINENO: checking for $ac_func" >&5
|
echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
dnl $Header: /cvsroot/pgsql/configure.in,v 1.301.2.16 2005/12/09 20:53:26 tgl Exp $
|
dnl $Header: /cvsroot/pgsql/configure.in,v 1.301.2.17 2006/01/05 00:51:25 tgl Exp $
|
||||||
dnl
|
dnl
|
||||||
dnl Developers, please strive to achieve this order:
|
dnl Developers, please strive to achieve this order:
|
||||||
dnl
|
dnl
|
||||||
@ -929,7 +929,7 @@ else
|
|||||||
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
|
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
|
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv])
|
||||||
|
|
||||||
# system's version of getaddrinfo(), if any, may be used only if we found
|
# system's version of getaddrinfo(), if any, may be used only if we found
|
||||||
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
|
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
|
||||||
|
@ -527,6 +527,9 @@
|
|||||||
/* Define to 1 if you have unix sockets. */
|
/* Define to 1 if you have unix sockets. */
|
||||||
#undef HAVE_UNIX_SOCKETS
|
#undef HAVE_UNIX_SOCKETS
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `unsetenv' function. */
|
||||||
|
#undef HAVE_UNSETENV
|
||||||
|
|
||||||
/* Define to 1 if you have the `utime' function. */
|
/* Define to 1 if you have the `utime' function. */
|
||||||
#undef HAVE_UTIME
|
#undef HAVE_UTIME
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: port.h,v 1.14 2003/09/13 14:49:51 momjian Exp $
|
* $Id: port.h,v 1.14.2.1 2006/01/05 00:51:25 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -105,6 +105,10 @@ extern char *strdup(char const *);
|
|||||||
extern long random(void);
|
extern long random(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_UNSETENV
|
||||||
|
extern void unsetenv(const char *name);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_SRANDOM
|
#ifndef HAVE_SRANDOM
|
||||||
extern void srandom(unsigned int seed);
|
extern void srandom(unsigned int seed);
|
||||||
#endif
|
#endif
|
||||||
|
56
src/port/unsetenv.c
Normal file
56
src/port/unsetenv.c
Normal file
@ -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.2.1 2006/01/05 00:51:25 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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user