Commit in reactos/lib/msvcrt/misc on MAIN
environ.c+14-71.6 -> 1.7
Fix environment variable handling. The (optional) envp argument to main() shall not contain strings of the form "=C:=C:\directory\".

reactos/lib/msvcrt/misc
environ.c 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- environ.c	24 Dec 2003 23:20:08 -0000	1.6
+++ environ.c	21 Feb 2004 08:02:49 -0000	1.7
@@ -1,4 +1,4 @@
-/* $Id: environ.c,v 1.6 2003/12/24 23:20:08 sedwards Exp $
+/* $Id: environ.c,v 1.7 2004/02/21 08:02:49 tamlin Exp $
  *
  * dllmain.c
  *
@@ -43,7 +43,7 @@
 int BlockEnvToEnviron(void)
 {
     char * ptr, * ptr2;
-    int i, len;
+    int i, count;
 
     DPRINT("BlockEnvToEnviron()\n");
 
@@ -57,18 +57,25 @@
         DPRINT("GetEnvironmentStringsA() returnd NULL\n");
         return -1;
     }
-    len = 0;
+    count = 0;
     while (*ptr2) {
-        len++;
+        /* skip current directory of the form "=C:=C:\directory\" */
+        if (*ptr2 != '=') {
+            count++;
+        }
         ptr2 += strlen(ptr2) + 1;
     }
-    _environ = malloc((len + 1) * sizeof(char*));
+    _environ = malloc((count + 1) * sizeof(char*));
     if (_environ == NULL) {
         FreeEnvironmentStringsA(ptr);
         return -1;
     }
-    for (i = 0; i < len && *ptr; i++) {
-        _environ[i] = ptr;
+    i = 0;
+    while (i < count && *ptr) {
+        if (*ptr != '=') {
+            _environ[i] = ptr;
+            ++i;
+        }
         ptr += strlen(ptr) + 1;
     }
     _environ[i] = NULL;
CVSspam 0.2.8