]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix the MS-Windows build after 2011-02-26T05:54:36Z!eggert@cs.ucla.edu.
authorEli Zaretskii <eliz@gnu.org>
Sat, 26 Feb 2011 07:44:38 +0000 (09:44 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 26 Feb 2011 07:44:38 +0000 (09:44 +0200)
 emacsclient.c (xstrdup) [WINDOWSNT]: Function added back.
 (w32_getenv): Use xstrdup to return all values in malloc'ed
 storage.

lib-src/ChangeLog
lib-src/emacsclient.c

index ba77a92cf1780f7c83c30f5c69306f5a8714f31e..b330a447d54201caf17388a94e065dd92b8c16df 100644 (file)
@@ -1,3 +1,9 @@
+2011-02-26  Eli Zaretskii  <eliz@gnu.org>
+
+       * emacsclient.c (xstrdup) [WINDOWSNT]: Function added back.
+       (w32_getenv): Use xstrdup to return all values in malloc'ed
+       storage.
+
 2011-02-26  Paul Eggert  <eggert@cs.ucla.edu>
 
        * ebrowse.c (parse_qualified_param_ident_or_type): Make it clear
index 251f35873e3880c4129c77728312b9d159d40350..836891ae6aa768b391069fc28d1d64cb2a9818ac 100644 (file)
@@ -293,6 +293,20 @@ get_current_dir_name (void)
 
 #ifdef WINDOWSNT
 
+/* Like strdup but get a fatal error if memory is exhausted. */
+
+char *
+xstrdup (const char *s)
+{
+  char *result = strdup (s);
+  if (result == NULL)
+    {
+      perror ("strdup");
+      exit (EXIT_FAILURE);
+    }
+  return result;
+}
+
 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
 
 /* Retrieve an environment variable from the Emacs subkeys of the registry.
@@ -328,9 +342,11 @@ w32_get_resource (HKEY predefined, char *key, LPDWORD type)
 /*
   getenv wrapper for Windows
 
-  This is needed to duplicate Emacs's behavior, which is to look for environment
-  variables in the registry if they don't appear in the environment.
-*/
+  Value is allocated on the heap, and can be free'd.
+
+  This is needed to duplicate Emacs's behavior, which is to look for
+  environment variables in the registry if they don't appear in the
+  environment.  */
 char *
 w32_getenv (char *envvar)
 {
@@ -338,15 +354,16 @@ w32_getenv (char *envvar)
   DWORD dwType;
 
   if (value = getenv (envvar))
-    /* Found in the environment.  */
-    return value;
+    /* Found in the environment.  strdup it, because values returned
+       by getenv cannot be free'd.  */
+    return xstrdup (value);
 
   if (! (value = w32_get_resource (HKEY_CURRENT_USER, envvar, &dwType)) &&
       ! (value = w32_get_resource (HKEY_LOCAL_MACHINE, envvar, &dwType)))
     {
       /* "w32console" is what Emacs on Windows uses for tty-type under -nw.  */
       if (strcmp (envvar, "TERM") == 0)
-       return "w32console";
+       return xstrdup ("w32console");
       /* Found neither in the environment nor in the registry.  */
       return NULL;
     }