]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Rename output_tmpfile() to a misc function get_tmpfile()
authorPaul Smith <psmith@gnu.org>
Sat, 11 Feb 2017 18:42:37 +0000 (13:42 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 4 Jun 2017 22:37:21 +0000 (18:37 -0400)
* output.c: Remove output_tmpfile() and umask handling.
* output.h: Ditto.
* misc.c: Add get_tmpfile() and umask handling.
* makeint.h: Ditto.
* function.c: Rename output_tmpfile() to get_tmpfile().
* main.c: Ditto.
* vmsjobs.c: Ditto.

function.c
main.c
makeint.h
misc.c
output.c
output.h
vmsjobs.c

index 7a2fcd4bc80495c649bd392bf06ff0bee45aa0d2..8d8f198f71168dd750e17ee314120a00e798dce6 100644 (file)
@@ -1924,9 +1924,8 @@ func_shell_base (char *o, char **argv, int trim_newlines)
     return o;
 
   /* Note the mktemp() is a security hole, but this only runs on Amiga.
-     Ideally we would use output_tmpfile(), but this uses a special
-     Open(), not fopen(), and I'm not familiar enough with the code to mess
-     with it.  */
+     Ideally we would use get_tmpfile(), but this uses a special Open(), not
+     fopen(), and I'm not familiar enough with the code to mess with it.  */
   strcpy (tmp_output, "t:MakeshXXXXXXXX");
   mktemp (tmp_output);
   child_stdout = Open (tmp_output, MODE_NEWFILE);
diff --git a/main.c b/main.c
index 5dd539b802fee41addbe13969389596abe314b43..939a1577433817620d297c7cc0bb801e4b5a53a7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1824,7 +1824,7 @@ main (int argc, char **argv, char **envp)
 #endif /* !HAVE_DOS_PATHS */
 
             strcat (template, DEFAULT_TMPFILE);
-            outfile = output_tmpfile (&stdin_nm, template);
+            outfile = get_tmpfile (&stdin_nm, template);
             if (outfile == 0)
               pfatal_with_name (_("fopen (temporary file)"));
             while (!feof (stdin) && ! ferror (stdin))
index 53a895e3346a9f7ffc21e3778019bd6f0dce59c0..f7af77b36735ff6c046cae0fdd523aa2dc4a29a7 100644 (file)
--- a/makeint.h
+++ b/makeint.h
@@ -291,6 +291,14 @@ char *strerror (int errnum);
 char *strsignal (int signum);
 #endif
 
+#if defined(HAVE_UMASK)
+# define UMASK(_m)  umask (_m)
+# define MODE_T     mode_t
+#else
+# define UMASK(_m)  0
+# define MODE_T     int
+#endif
+
 /* ISDIGIT offers the following features:
    - Its arg may be any int or unsigned int; it need not be an unsigned char.
    - It's guaranteed to evaluate its argument exactly once.
@@ -520,6 +528,7 @@ int alpha_compare (const void *, const void *);
 void print_spaces (unsigned int);
 char *find_percent (char *);
 const char *find_percent_cached (const char **);
+FILE *get_tmpfile (char **, const char *);
 
 #ifndef NO_ARCHIVES
 int ar_name (const char *);
diff --git a/misc.c b/misc.c
index c9e88b61fe75a04f5d9d72079a41f0b2554c7c00..5dc1881d3e327bc1de8f69a2943fd6fb175bbfc4 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -23,6 +23,10 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <stdarg.h>
 
+#ifdef WINDOWS32
+# include <io.h>
+#endif
+
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #else
@@ -391,6 +395,67 @@ free_ns_chain (struct nameseq *ns)
 }
 \f
 
+/* Provide support for temporary files.  */
+
+#ifndef HAVE_STDLIB_H
+# ifdef HAVE_MKSTEMP
+int mkstemp (char *template);
+# else
+char *mktemp (char *template);
+# endif
+#endif
+
+FILE *
+get_tmpfile (char **name, const char *template)
+{
+  FILE *file;
+#ifdef HAVE_FDOPEN
+  int fd;
+#endif
+
+  /* Preserve the current umask, and set a restrictive one for temp files.  */
+  MODE_T mask = UMASK (0077);
+
+#if defined(HAVE_MKSTEMP) || defined(HAVE_MKTEMP)
+# define TEMPLATE_LEN   strlen (template)
+#else
+# define TEMPLATE_LEN   L_tmpnam
+#endif
+  *name = xmalloc (TEMPLATE_LEN + 1);
+  strcpy (*name, template);
+
+#if defined(HAVE_MKSTEMP) && defined(HAVE_FDOPEN)
+  /* It's safest to use mkstemp(), if we can.  */
+  EINTRLOOP (fd, mkstemp (*name));
+  if (fd == -1)
+    file = NULL;
+  else
+    file = fdopen (fd, "w");
+#else
+# ifdef HAVE_MKTEMP
+  (void) mktemp (*name);
+# else
+  (void) tmpnam (*name);
+# endif
+
+# ifdef HAVE_FDOPEN
+  /* Can't use mkstemp(), but guard against a race condition.  */
+  EINTRLOOP (fd, open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600));
+  if (fd == -1)
+    return 0;
+  file = fdopen (fd, "w");
+# else
+  /* Not secure, but what can we do?  */
+  file = fopen (*name, "w");
+# endif
+#endif
+
+  UMASK (mask);
+
+  return file;
+}
+\f
+
 #if !HAVE_STRCASECMP && !HAVE_STRICMP && !HAVE_STRCMPI
 /* If we don't have strcasecmp() (from POSIX), or anything that can substitute
    for it, define our own version.  */
index 4945433db3da34ca837a1d927a63d3ca63a5a0a0..142a9642bf05cb867900a66aabdfe2cff6a56296 100644 (file)
--- a/output.c
+++ b/output.c
@@ -53,14 +53,6 @@ unsigned int stdio_traced = 0;
 # define STREAM_OK(_s) 1
 #endif
 
-#if defined(HAVE_UMASK)
-# define UMASK(_m)  umask (_m)
-# define MODE_T     mode_t
-#else
-# define UMASK(_m)  0
-# define MODE_T     int
-#endif
-
 /* Write a BUFFER of size LEN to file descriptor FD.
    Handle EINTR and other short writes.  If we get an error, ignore it.  */
 int
@@ -428,67 +420,6 @@ output_dump (struct output *out)
 #endif /* NO_OUTPUT_SYNC */
 \f
 
-/* Provide support for temporary files.  */
-
-#ifndef HAVE_STDLIB_H
-# ifdef HAVE_MKSTEMP
-int mkstemp (char *template);
-# else
-char *mktemp (char *template);
-# endif
-#endif
-
-FILE *
-output_tmpfile (char **name, const char *template)
-{
-  FILE *file;
-#ifdef HAVE_FDOPEN
-  int fd;
-#endif
-
-  /* Preserve the current umask, and set a restrictive one for temp files.  */
-  MODE_T mask = UMASK (0077);
-
-#if defined(HAVE_MKSTEMP) || defined(HAVE_MKTEMP)
-# define TEMPLATE_LEN   strlen (template)
-#else
-# define TEMPLATE_LEN   L_tmpnam
-#endif
-  *name = xmalloc (TEMPLATE_LEN + 1);
-  strcpy (*name, template);
-
-#if defined(HAVE_MKSTEMP) && defined(HAVE_FDOPEN)
-  /* It's safest to use mkstemp(), if we can.  */
-  EINTRLOOP (fd, mkstemp (*name));
-  if (fd == -1)
-    file = NULL;
-  else
-    file = fdopen (fd, "w");
-#else
-# ifdef HAVE_MKTEMP
-  (void) mktemp (*name);
-# else
-  (void) tmpnam (*name);
-# endif
-
-# ifdef HAVE_FDOPEN
-  /* Can't use mkstemp(), but guard against a race condition.  */
-  EINTRLOOP (fd, open (*name, O_CREAT|O_EXCL|O_WRONLY, 0600));
-  if (fd == -1)
-    return 0;
-  file = fdopen (fd, "w");
-# else
-  /* Not secure, but what can we do?  */
-  file = fopen (*name, "w");
-# endif
-#endif
-
-  UMASK (mask);
-
-  return file;
-}
-\f
-
 /* This code is stolen from gnulib.
    If/when we abandon the requirement to work with K&R compilers, we can
    remove this (and perhaps other parts of GNU make!) and migrate to using
index b398cdd02d707a5d986791fb92a37ec0d40795ae..083cd246e7d744d2b6b74ce5307dc3ab0c79baa7 100644 (file)
--- a/output.h
+++ b/output.h
@@ -34,8 +34,6 @@ extern unsigned int stdio_traced;
 #define OUTPUT_TRACED()     do{ stdio_traced = 1; }while(0)
 #define OUTPUT_IS_TRACED()  (!!stdio_traced)
 
-FILE *output_tmpfile (char **, const char *);
-
 /* Write a buffer directly to the given file descriptor.
    This handles errors etc.  */
 int output_write (int fd, const void *buffer, size_t len);
index f45c8a80a971121e97f0287c1384d2f5d80bb9af..77a142ebf4951843ead0fd124693fb06cd25ee1a 100644 (file)
--- a/vmsjobs.c
+++ b/vmsjobs.c
@@ -1245,9 +1245,9 @@ child_execute_job (struct child *child, char *argv)
       FILE *outfile;
       int cmd_len;
 
-      outfile = output_tmpfile (&child->comname,
-                                "sys$scratch:gnv$make_cmdXXXXXX.com");
-      /*                                          012345678901234567890 */
+      outfile = get_tmpfile (&child->comname,
+                             "sys$scratch:gnv$make_cmdXXXXXX.com");
+      /*                      123456789012345678901234567890 */
       if (outfile == 0)
         pfatal_with_name (_("fopen (temporary file)"));
       comnamelen = strlen (child->comname);