]> git.ipfire.org Git - thirdparty/make.git/commitdiff
tests: Preserve Windows temp environment variables
authorPaul Smith <psmith@gnu.org>
Sun, 27 Feb 2022 22:44:16 +0000 (17:44 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 27 Feb 2022 22:47:19 +0000 (17:47 -0500)
* src/main.c (main): Show the temp filename on error.  Also on
Windows prefer TMP, then TEMP, and only lastly TMPDIR.
* tests/test_driver.pl: Add TMP, TEMP, and USERPROFILE to the list
of environment variables to preserve.

src/main.c
tests/test_driver.pl

index 7df05d806a807033807b99d896f0bbd504b260a1..0554e526267aa709de9ebde5ef4b12e8d9cfb860 100644 (file)
@@ -1799,13 +1799,12 @@ main (int argc, char **argv, char **envp)
 #endif
 #define DEFAULT_TMPFILE     "GmXXXXXX"
 
-            if (((tmpdir = getenv ("TMPDIR")) == NULL || *tmpdir == '\0')
+            if (
 #if defined (__MSDOS__) || defined (WINDOWS32) || defined (__EMX__)
-                /* These are also used commonly on these platforms.  */
-                && ((tmpdir = getenv ("TEMP")) == NULL || *tmpdir == '\0')
-                && ((tmpdir = getenv ("TMP")) == NULL || *tmpdir == '\0')
+                ((tmpdir = getenv ("TMP")) == NULL || *tmpdir == '\0') &&
+                ((tmpdir = getenv ("TEMP")) == NULL || *tmpdir == '\0') &&
 #endif
-               )
+                ((tmpdir = getenv ("TMPDIR")) == NULL || *tmpdir == '\0'))
               tmpdir = DEFAULT_TMPDIR;
 
             template = alloca (strlen (tmpdir) + CSTRLEN (DEFAULT_TMPFILE) + 2);
@@ -1824,13 +1823,15 @@ main (int argc, char **argv, char **envp)
             strcat (template, DEFAULT_TMPFILE);
             outfile = get_tmpfile (&stdin_nm, template);
             if (outfile == 0)
-              pfatal_with_name (_("fopen (temporary file)"));
+              OSS (fatal, NILF,
+                   _("fopen: temporary file %s: %s"), newnm, strerror (errno));
             while (!feof (stdin) && ! ferror (stdin))
               {
                 char buf[2048];
                 size_t n = fread (buf, 1, sizeof (buf), stdin);
                 if (n > 0 && fwrite (buf, 1, n, outfile) != n)
-                  pfatal_with_name (_("fwrite (temporary file)"));
+                  OSS (fatal, NILF,
+                       _("fwrite: temporary file %s: %s"), newnm, strerror (errno));
               }
             fclose (outfile);
 
index 71aefac9a2ac3f4f7ff50039887eb0c316bc30b4..5522ac11b1dfd364f6253a810b6834ed46f09b85 100644 (file)
@@ -173,16 +173,16 @@ sub toplevel
 {
   # Pull in benign variables from the user's environment
 
-  foreach (# UNIX-specific things
+  foreach (# POSIX-specific things
            'TZ', 'TMPDIR', 'HOME', 'USER', 'LOGNAME', 'PATH',
            'LD_LIBRARY_PATH',
-           # SAN things
+           # *SAN things
            'ASAN_OPTIONS', 'UBSAN_OPTIONS',
            # Purify things
            'PURIFYOPTIONS',
-           # Windows NT-specific stuff
-           'Path', 'SystemRoot',
-           # DJGPP-specific stuff
+           # Windows-specific things
+           'Path', 'SystemRoot', 'TEMP', 'TMP', 'USERPROFILE',
+           # DJGPP-specific things
            'DJDIR', 'DJGPP', 'SHELL', 'COMSPEC', 'HOSTNAME', 'LFN',
            'FNCASE', '387', 'EMU387', 'GROUP'
           ) {