https://gcc.gnu.org/g:6dc59fc713269b23cc8ad7b622bcb3009690a650

commit r17-1200-g6dc59fc713269b23cc8ad7b622bcb3009690a650
Author: Mathias Aparicio <[email protected]>
Date:   Mon Apr 13 16:18:56 2026 +0200

    ada: Expand check for setenv availability with _POSIX_VERSION
    
    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.

Diff:
---
 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 d37d2bc7a02d..254fe4dbbcfb 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;

Reply via email to