Hi,

Thanks Noam.
Yes, the case is handled for getenv. 
The problem seems to be with setenv.
The following is a possible fix.

diff --git a/lisp/env.el b/lisp/env.el
index 859f280802..c93be80e84 100644
--- a/lisp/env.el
+++ b/lisp/env.el
@@ -105,7 +105,7 @@ setenv-internal
   "Set VARIABLE to VALUE in ENV, adding empty entries if KEEP-EMPTY.
 Changes ENV by side-effect, and returns its new value."
   (let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)"))
-       (case-fold-search nil)
+       (case-fold-search (memq system-type '(ms-dos windows-nt))
        (scan env)
        prev found)
     ;; Handle deletions from the beginning of the list specially.

Fabrice

2017-06-11 23:33 GMT+02:00 Noam Postavsky <npostavs@users.sourceforge.net>:
On Sun, Jun 11, 2017 at 4:33 PM, Fabrice Popineau
<fabrice.popineau@gmail.com> wrote:

> AFAIK, environment variables are case insensitive under Windows.
> So there is something that is not taken care of for the case of case
> insensitive environment variables.
> I haven't (yet) been able to find where this magic happens however.

It looks like there is code for it in callproc.c:

static bool
getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value,
           ptrdiff_t *valuelen, Lisp_Object env)
{
  for (; CONSP (env); env = XCDR (env))
    {
      Lisp_Object entry = XCAR (env);
      if (STRINGP (entry)
      && SBYTES (entry) >= varlen
#ifdef WINDOWSNT
      /* NT environment variables are case insensitive.  */
      && ! strnicmp (SSDATA (entry), var, varlen)