Merge from emacs-24; up to 2012-12-19T19:51:40Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / src / callproc.c
index ea79da7..9132c0d 100644 (file)
@@ -997,13 +997,11 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
     tmpdir = Vtemporary_file_directory;
   else
     {
+      char *outf;
 #ifndef DOS_NT
-      if (getenv ("TMPDIR"))
-       tmpdir = build_string (getenv ("TMPDIR"));
-      else
-       tmpdir = build_string ("/tmp/");
+      outf = getenv ("TMPDIR");
+      tmpdir = build_string (outf ? outf : "/tmp/");
 #else /* DOS_NT */
-      char *outf;
       if ((outf = egetenv ("TMPDIR"))
          || (outf = egetenv ("TMP"))
          || (outf = egetenv ("TEMP")))
@@ -1016,8 +1014,26 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
   {
     USE_SAFE_ALLOCA;
     Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
-    Lisp_Object encoded_tem = ENCODE_FILE (pattern);
-    char *tempfile = SAFE_ALLOCA (SBYTES (encoded_tem) + 1);
+    Lisp_Object encoded_tem;
+    char *tempfile;
+
+#ifdef WINDOWSNT
+    /* Cannot use the result of Fexpand_file_name, because it
+       downcases the XXXXXX part of the pattern, and mktemp then
+       doesn't recognize it.  */
+    if (!NILP (Vw32_downcase_file_names))
+      {
+       Lisp_Object dirname = Ffile_name_directory (pattern);
+
+       if (NILP (dirname))
+         pattern = Vtemp_file_name_pattern;
+       else
+         pattern = concat2 (dirname, Vtemp_file_name_pattern);
+      }
+#endif
+
+    encoded_tem = ENCODE_FILE (pattern);
+    tempfile = SAFE_ALLOCA (SBYTES (encoded_tem) + 1);
     memcpy (tempfile, SDATA (encoded_tem), SBYTES (encoded_tem) + 1);
     coding_systems = Qt;
 
@@ -1637,7 +1653,7 @@ init_callproc (void)
   if (! file_accessible_directory_p (SSDATA (tempdir)))
     dir_warning ("arch-independent data dir", Vdata_directory);
 
-  sh = (char *) getenv ("SHELL");
+  sh = getenv ("SHELL");
   Vshell_file_name = build_string (sh ? sh : "/bin/sh");
 
 #ifdef DOS_NT