diff src/w32.c @ 90428:a8190f7e546e

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 285-296) - Update from CVS - Merge from gnus--rel--5.10 - Update from CVS: admin/FOR-RELEASE: Update refcard section. * gnus--rel--5.10 (patch 102-104) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
author Miles Bader <miles@gnu.org>
date Wed, 07 Jun 2006 18:05:10 +0000
parents 5754737d1e04 f263eba56074
children 8a8e69664178
line wrap: on
line diff
--- a/src/w32.c	Wed Jun 07 11:41:58 2006 +0000
+++ b/src/w32.c	Wed Jun 07 18:05:10 2006 +0000
@@ -950,11 +950,11 @@
     struct stat ignored;
     char default_home[MAX_PATH];
 
-    static struct env_entry
+    static const struct env_entry
     {
       char * name;
       char * def_value;
-    } env_vars[] =
+    } dflt_envvars[] =
     {
       {"HOME", "C:/"},
       {"PRELOAD_WINSOCK", NULL},
@@ -971,6 +971,17 @@
       {"LANG", NULL},
     };
 
+#define N_ENV_VARS sizeof(dflt_envvars)/sizeof(dflt_envvars[0])
+
+    /* We need to copy dflt_envvars[] and work on the copy because we
+       don't want the dumped Emacs to inherit the values of
+       environment variables we saw during dumping (which could be on
+       a different system).  The defaults above must be left intact.  */
+    struct env_entry env_vars[N_ENV_VARS];
+
+    for (i = 0; i < N_ENV_VARS; i++)
+      env_vars[i] = dflt_envvars[i];
+
     /* For backwards compatibility, check if a .emacs file exists in C:/
        If not, then we can try to default to the appdata directory under the
        user's profile, which is more likely to be writable.   */
@@ -1005,7 +1016,7 @@
                      LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
                      locale_name, sizeof (locale_name)))
     {
-      for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
+      for (i = 0; i < N_ENV_VARS; i++)
         {
           if (strcmp (env_vars[i].name, "LANG") == 0)
             {
@@ -1069,7 +1080,7 @@
 	}
     }
 
-    for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
+    for (i = 0; i < N_ENV_VARS; i++)
       {
 	if (!getenv (env_vars[i].name))
 	  {
@@ -1084,21 +1095,18 @@
 
 	    if (lpval)
 	      {
+		char buf1[SET_ENV_BUF_SIZE], buf2[SET_ENV_BUF_SIZE];
+
 		if (dwType == REG_EXPAND_SZ)
+		  ExpandEnvironmentStrings ((LPSTR) lpval, buf1, sizeof(buf1));
+		else if (dwType == REG_SZ)
+		  strcpy (buf1, lpval);
+		if (dwType == REG_EXPAND_SZ || dwType == REG_SZ)
 		  {
-		    char buf1[SET_ENV_BUF_SIZE], buf2[SET_ENV_BUF_SIZE];
-
-		    ExpandEnvironmentStrings ((LPSTR) lpval, buf1, sizeof(buf1));
-		    _snprintf (buf2, sizeof(buf2)-1, "%s=%s", env_vars[i].name, buf1);
+		    _snprintf (buf2, sizeof(buf2)-1, "%s=%s", env_vars[i].name,
+			       buf1);
 		    _putenv (strdup (buf2));
 		  }
-		else if (dwType == REG_SZ)
-		  {
-		    char buf[SET_ENV_BUF_SIZE];
-
-		    _snprintf (buf, sizeof(buf)-1, "%s=%s", env_vars[i].name, lpval);
-		    _putenv (strdup (buf));
-		  }
 
 		if (!dont_free)
 		  xfree (lpval);