mirror of
https://github.com/mirror/make.git
synced 2025-03-04 06:40:56 +08:00
Rename output_tmpfile() to a misc function get_tmpfile()
* 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.
This commit is contained in:
parent
68be4f74fc
commit
5acc59c704
@ -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);
|
||||
|
2
main.c
2
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))
|
||||
|
@ -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 *);
|
||||
|
65
misc.c
65
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)
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
#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. */
|
||||
|
69
output.c
69
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 */
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
/* 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
|
||||
|
2
output.h
2
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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user