* 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.
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);
#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))
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.
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 *);
#include <stdarg.h>
+#ifdef WINDOWS32
+# include <io.h>
+#endif
+
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#else
}
\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. */
# 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
#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
#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);
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);