Subject: Re: leading '=' in enviroment variable truncated
From: Peter Stephenson <[email-masked]>
To: [email-masked]
Date: Sun, 8 May 2016 21:28:58 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

[apologies for duplicates, I think I sent the last reply to Bart.]

On Sun, 8 May 2016 13:24:06 -0700
Bart Schaefer <[email-masked]> wrote:
> Astounding.
> 
> The Open Group spec for "setenv" explicitly prohibits "=" in the name,
> and says nothing about the value.  The source code for setenv.c on
> opensource.apple.com does nothing special with name or value.
> 
> How about this?

This tries to be smarter, but I don't know if it's worth it... it's
untested on the target system.

diff --git a/Src/zsh_system.h b/Src/zsh_system.h
index 811340d..4f3330b 100644
--- a/Src/zsh_system.h
+++ b/Src/zsh_system.h
@@ -729,7 +729,9 @@ extern char **environ;
  * we don't know how to do memory management on the values set.
  */
 #if defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
-# define USE_SET_UNSET_ENV
+# ifndef SETENV_MANGLES_EQUALS
+#  define USE_SET_UNSET_ENV
+# endif
 #endif

diff --git a/configure.ac b/configure.ac
index 9ce3a45..b5be67f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3031,6 +3031,27 @@ if test "x$dynamic" = xyes; then
   fi
 fi
 
+AH_TEMPLATE([SETENV_MANGLES_EQUALS],
+[Define to 1 if setenv removes a leading =])
+if test x$ac_cv_func_setsnv = xyes; then
+AC_CACHE_CHECK([if setenv removes a leading =],
+ zsh_cv_c_setenv_mangles_equals,
+ [AC_TRY_RUN([
+#include <string.h>
+   main()
+   {
+      setenv("NAME", "=VALUE", 1);
+      return strcmp((char *)getenv("NAME"), "=VALUE");
+   }
+   ],
+   zsh_cv_c_setenv_mangles_equals=yes,
+   zsh_cv_c_setenv_mangles_equals=no,
+   zsh_cv_c_setenv_mangles_equals=no)])
+   if test x$zsh_cv_c_setenv_mangles_equals = xyes; then
+     AC_DEFINE(SETENV_MANGLES_EQUALS)
+   fi
+fi
+
 if test "x$dynamic" = xyes; then
   zsh_SYS_DYNAMIC_CLASH
   zsh_SYS_DYNAMIC_GLOBAL