Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2020-12-30 17:55:59 +0000
committerTom Lane2020-12-30 17:56:06 +0000
commit7ca37fb0406bc2cbbd864a2ffdbdb4479e338c0c (patch)
tree69fac5bdeef7caed09a8e57ca7aeddd2d97a0e48 /configure.ac
parent62097a4cc8c725fa86d3170396a8f30609acd0d3 (diff)
Use setenv() in preference to putenv().
Since at least 2001 we've used putenv() and avoided setenv(), on the grounds that the latter was unportable and not in POSIX. However, POSIX added it that same year, and by now the situation has reversed: setenv() is probably more portable than putenv(), since POSIX now treats the latter as not being a core function. And setenv() has cleaner semantics too. So, let's reverse that old policy. This commit adds a simple src/port/ implementation of setenv() for any stragglers (we have one in the buildfarm, but I'd not be surprised if that code is never used in the field). More importantly, extend win32env.c to also support setenv(). Then, replace usages of putenv() with setenv(), and get rid of some ad-hoc implementations of setenv() wannabees. Also, adjust our src/port/ implementation of unsetenv() to follow the POSIX spec that it returns an error indicator, rather than returning void as per the ancient BSD convention. I don't feel a need to make all the call sites check for errors, but the portability stub ought to match real-world practice. Discussion: https://postgr.es/m/2065122.1609212051@sss.pgh.pa.us
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac4
1 files changed, 3 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index fc523c6aeb4..7f855783f4e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1757,11 +1757,13 @@ fi
case $host_os in
# Windows uses a specialised env handler
mingw*)
+ AC_DEFINE(HAVE_SETENV, 1, [Define to 1 because replacement version used.])
AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
+ ac_cv_func_setenv=yes
ac_cv_func_unsetenv=yes
;;
*)
- AC_REPLACE_FUNCS([unsetenv])
+ AC_REPLACE_FUNCS([setenv unsetenv])
;;
esac