Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e16195

Browse files
committed
Second try at a portable unsetenv().
1 parentdadce65 commit9e16195

File tree

6 files changed

+71
-25
lines changed

6 files changed

+71
-25
lines changed

‎configure

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11744,7 +11744,8 @@ fi
1174411744

1174511745

1174611746

11747-
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul
11747+
11748+
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv
1174811749
do
1174911750
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1175011751
echo "$as_me:$LINENO: checking for $ac_func" >&5

‎configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.343 2004/04/30 16:08:01 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.344 2004/05/05 21:18:29 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -858,7 +858,7 @@ else
858858
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
859859
fi
860860

861-
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul])
861+
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strcasecmp strdup strerror strtol strtoul unsetenv])
862862

863863
# system's version of getaddrinfo(), if any, may be used only if we found
864864
# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h

‎src/bin/initdb/initdb.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
* Portions taken from FreeBSD.
4545
*
46-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.24 2004/05/0516:09:31 tgl Exp $
46+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.25 2004/05/0521:18:29 tgl Exp $
4747
*
4848
*-------------------------------------------------------------------------
4949
*/
@@ -263,24 +263,6 @@ xstrdup(const char *s)
263263
returnresult;
264264
}
265265

266-
/*
267-
* unsetenv() doesn't exist everywhere, so emulate it with this ugly
268-
* but well-tested technique (borrowed from backend's variable.c).
269-
*/
270-
staticvoid
271-
pg_unsetenv(constchar*varname)
272-
{
273-
char*envstr=xmalloc(strlen(varname)+2);
274-
275-
/* First, override any existing setting by forcibly defining the var */
276-
sprintf(envstr,"%s=",varname);
277-
putenv(envstr);
278-
279-
/* Now we can clobber the variable definition this way: */
280-
strcpy(envstr,"=");
281-
putenv(envstr);
282-
}
283-
284266
/*
285267
* delete a directory tree recursively
286268
* assumes path points to a valid directory
@@ -1260,10 +1242,10 @@ bootstrap_template1(char *short_version)
12601242
snprintf(cmd,sizeof(cmd),"LC_CTYPE=%s",lc_ctype);
12611243
putenv(xstrdup(cmd));
12621244

1263-
pg_unsetenv("LC_ALL");
1245+
unsetenv("LC_ALL");
12641246

12651247
/* Also ensure backend isn't confused by this environment var: */
1266-
pg_unsetenv("PGCLIENTENCODING");
1248+
unsetenv("PGCLIENTENCODING");
12671249

12681250
snprintf(cmd,sizeof(cmd),
12691251
"\"%s/postgres\" -boot -x1 %s %s template1",

‎src/include/c.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.162 2004/04/30 20:47:33 momjian Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.163 2004/05/05 21:18:29 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -720,6 +720,10 @@ extern intvsnprintf(char *str, size_t count, const char *fmt, va_list args);
720720
#definememmove(d,s,c)bcopy(s, d, c)
721721
#endif
722722

723+
#ifndefHAVE_UNSETENV
724+
externvoidunsetenv(constchar*name);
725+
#endif
726+
723727
#ifndefDLLIMPORT
724728
#defineDLLIMPORT/* no special DLL markers on most ports */
725729
#endif

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@
530530
/* Define to 1 if you have unix sockets. */
531531
#undef HAVE_UNIX_SOCKETS
532532

533+
/* Define to 1 if you have the `unsetenv' function. */
534+
#undef HAVE_UNSETENV
535+
533536
/* Define to 1 if you have the `utime' function. */
534537
#undef HAVE_UTIME
535538

‎src/port/unsetenv.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* unsetenv.c
4+
* unsetenv() emulation for machines without it
5+
*
6+
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* $PostgreSQL: pgsql/src/port/unsetenv.c,v 1.1 2004/05/05 21:18:29 tgl Exp $
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
16+
#include"c.h"
17+
18+
19+
void
20+
unsetenv(constchar*name)
21+
{
22+
char*envstr;
23+
24+
if (getenv(name)==NULL)
25+
return;/* no work */
26+
27+
/*
28+
* The technique embodied here works if libc follows the Single Unix Spec
29+
* and actually uses the storage passed to putenv() to hold the environ
30+
* entry. When we clobber the entry in the second step we are ensuring
31+
* that we zap the actual environ member. However, there are some libc
32+
* implementations (notably recent BSDs) that do not obey SUS but copy
33+
* the presented string. This method fails on such platforms. Hopefully
34+
* all such platforms have unsetenv() and thus won't be using this hack.
35+
*
36+
* Note that repeatedly setting and unsetting a var using this code
37+
* will leak memory.
38+
*/
39+
40+
envstr= (char*)malloc(strlen(name)+2);
41+
if (!envstr)/* not much we can do if no memory */
42+
return;
43+
44+
/* Override the existing setting by forcibly defining the var */
45+
sprintf(envstr,"%s=",name);
46+
putenv(envstr);
47+
48+
/* Now we can clobber the variable definition this way: */
49+
strcpy(envstr,"=");
50+
51+
/*
52+
* This last putenv cleans up if we have multiple zero-length names
53+
* as a result of unsetting multiple things.
54+
*/
55+
putenv(envstr);
56+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp