From: Mathias Aparicio <[email protected]>

Before this patch, the check for setenv availability was hard-coded to a
fixed list of platforms. Now expand the OR clause to also accept any system
conforming to ISO POSIX.1-2001, which includes setenv in unistd.h. This
avoids falling back to the putenv-based #else branch on other
POSIX-compliant systems.

gcc/ada/ChangeLog:

        * env.c (__gnat_setenv): Add _POSIX_VERSION >= 200112L to setenv
        availability check.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/env.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/env.c b/gcc/ada/env.c
index d37d2bc7a02..254fe4dbbcf 100644
--- a/gcc/ada/env.c
+++ b/gcc/ada/env.c
@@ -99,12 +99,16 @@ __gnat_getenv (char *name, int *len, char **value)
 void
 __gnat_setenv (char *name, char *value)
 {
+/* We use setenv on a few operating systems where we are sure it's available,
+   plus on all platforms that claim to support a POSIX version where setenv is
+   mandatory */
 #if (defined (__vxworks) && (defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7)) \
     || defined (__APPLE__) \
-    || defined (__linux__)
+    || defined (__linux__) \
+    || _POSIX_VERSION >= 200112L
   setenv (name, value, 1);
 
-#else /* Why don't we use setenv on all platforms where it's available??? */
+#else
   size_t size = strlen (name) + strlen (value) + 2;
   char *expression;
 
-- 
2.53.0

Reply via email to