This makes getenv return sensibly before the environment is initialized.
The attached file should be properly formatted (Changelog & patch), which my mailer can't do.

Pierre


2006-04-06  Pierre Humblet [EMAIL PROTECTED]

       * environ.cc (getearly): New function.
          (getenv) : Call getearly if needed.
Index: environ.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/environ.cc,v
retrieving revision 1.139
diff -u -p -b -r1.139 environ.cc
--- environ.cc  22 Mar 2006 16:42:44 -0000      1.139
+++ environ.cc  6 Apr 2006 16:06:05 -0000
@@ -224,6 +224,39 @@ my_findenv (const char *name, int *offse
}

/*
+ * getearly --
+ *     Primitive getenv before the environment is built.
+ */
+
+static char *
+getearly (const char * name)
+{
+  int s = strlen (name);
+  char * rawenv;
+  char ** ptr;
+  child_info *get_cygwin_startup_info ();
+  child_info_spawn *ci = (child_info_spawn *) get_cygwin_startup_info ();
+
+ if (ci && (ptr = ci->moreinfo->envp)) + {
+      for (; *ptr; ptr++)
+       if (strncasematch (name, *ptr, s)
+           && (*(*ptr + s) == '='))
+         return *ptr + s + 1;
+    }
+  else if ((rawenv = GetEnvironmentStrings ()))
+    {
+      while (*rawenv)
+       if (strncasematch (name, rawenv, s)
+           && (*(rawenv + s) == '='))
+         return rawenv + s + 1;
+       else
+         rawenv = strchr (rawenv, 0) + 1;
+    }
+  return NULL;
+}
+
+/*
 * getenv --
 *     Returns ptr to value associated with name, if any, else NULL.
 */
@@ -232,7 +265,8 @@ extern "C" char *
getenv (const char *name)
{
  int offset;
-
+  if (!__cygwin_environ)
+    return getearly (name);
  return my_findenv (name, &offset);
}

Attachment: environ.diff
Description: Binary data

Reply via email to