Commit 003ac91d by Jeffrey A Law Committed by Jeff Law

choose-temp.c (choose_temp_base): Remove MPW bits.

        * choose-temp.c (choose_temp_base): Remove MPW bits.  Use mkstemp
        instead of mktemp.
        * gcc.c (MKTEMP_EACH_FILE): Define.
        (main): No need to call choose_temp_base if we are going to
        use choose_temp_base to create each file later.
        * mkstemp.c: New file.  Adapted from glibc.
        * Makefile.in (xgcc, colect2, protoize, unprotoize): Link in mkstemp.o
        (mkstemp.o): Add dependencies.

From-SVN: r20746
parent 463b558b
Sat Jun 27 01:35:14 1998 Jeffrey A Law (law@cygnus.com)
* choose-temp.c (choose_temp_base): Remove MPW bits. Use mkstemp
instead of mktemp.
* gcc.c (MKTEMP_EACH_FILE): Define.
(main): No need to call choose_temp_base if we are going to
use choose_temp_base to create each file later.
* mkstemp.c: New file. Adapted from glibc.
* Makefile.in (xgcc, colect2, protoize, unprotoize): Link in mkstemp.o
(mkstemp.o): Add dependencies.
* configure.in (gettimeofday): Check for its existance.
* config.in (HAVE_GETTIMEOFDAY): Define.
* configure: Rebuilt.
1998-06-26 Michael Meissner <meissner@cygnus.com> 1998-06-26 Michael Meissner <meissner@cygnus.com>
* rs6000.md (ne 0, non power case): Add missing & constraint. * rs6000.md (ne 0, non power case): Add missing & constraint.
......
...@@ -840,9 +840,9 @@ stamp-objlist: $(OBJS) ...@@ -840,9 +840,9 @@ stamp-objlist: $(OBJS)
# to avoid confusion if the current directory is in the path # to avoid confusion if the current directory is in the path
# and CC is `gcc'. It is renamed to `gcc' when it is installed. # and CC is `gcc'. It is renamed to `gcc' when it is installed.
xgcc$(exeext): gcc.o version.o choose-temp.o pexecute.o prefix.o version.o \ xgcc$(exeext): gcc.o version.o choose-temp.o pexecute.o prefix.o version.o \
$(LIBDEPS) $(EXTRA_GCC_OBJS) mkstemp.o $(LIBDEPS) $(EXTRA_GCC_OBJS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ gcc.o prefix.o version.o \ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ gcc.o prefix.o version.o \
choose-temp.o pexecute.o $(EXTRA_GCC_OBJS) $(LIBS) choose-temp.o pexecute.o mkstemp.o $(EXTRA_GCC_OBJS) $(LIBS)
# Dump a specs file to make -B./ read these specs over installed ones. # Dump a specs file to make -B./ read these specs over installed ones.
specs: xgcc$(exeext) specs: xgcc$(exeext)
...@@ -1282,11 +1282,11 @@ c-iterate.o: c-iterate.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) c-tree.h \ ...@@ -1282,11 +1282,11 @@ c-iterate.o: c-iterate.c $(CONFIG_H) system.h $(TREE_H) $(RTL_H) c-tree.h \
flags.h toplev.h expr.h insn-codes.h flags.h toplev.h expr.h insn-codes.h
collect2$(exeext): collect2.o tlink.o hash.o cplus-dem.o underscore.o \ collect2$(exeext): collect2.o tlink.o hash.o cplus-dem.o underscore.o \
version.o choose-temp.o $(LIBDEPS) version.o choose-temp.o mkstemp.o $(LIBDEPS)
# Don't try modifying collect2 (aka ld) in place--it might be linking this. # Don't try modifying collect2 (aka ld) in place--it might be linking this.
-rm -f collect2$(exeext) -rm -f collect2$(exeext)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ collect2.o tlink.o hash.o \ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ collect2.o tlink.o hash.o \
cplus-dem.o underscore.o version.o choose-temp.o $(LIBS) cplus-dem.o underscore.o version.o choose-temp.o mkstemp.o $(LIBS)
collect2.o : collect2.c $(CONFIG_H) system.h gansidecl.h gstab.h obstack.h \ collect2.o : collect2.c $(CONFIG_H) system.h gansidecl.h gstab.h obstack.h \
$(DEMANGLE_H) $(DEMANGLE_H)
...@@ -1350,6 +1350,7 @@ dumpvers: dumpvers.c ...@@ -1350,6 +1350,7 @@ dumpvers: dumpvers.c
version.o: version.c version.o: version.c
obstack.o: obstack.c $(CONFIG_H) obstack.o: obstack.c $(CONFIG_H)
choose-temp.o: choose-temp.c $(CONFIG_H) gansidecl.h system.h choose-temp.o: choose-temp.c $(CONFIG_H) gansidecl.h system.h
mkstemp.o: mkstemp.c $(CONFIG_H) gansidecl.h system.h
pexecute.o: pexecute.c $(CONFIG_H) system.h gansidecl.h pexecute.o: pexecute.c $(CONFIG_H) system.h gansidecl.h
prefix.o: prefix.c $(CONFIG_H) system.h gansidecl.h Makefile prefix.o: prefix.c $(CONFIG_H) system.h gansidecl.h Makefile
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
...@@ -1862,16 +1863,16 @@ cppalloc.o: cppalloc.c $(CONFIG_H) cpplib.h system.h gansidecl.h ...@@ -1862,16 +1863,16 @@ cppalloc.o: cppalloc.c $(CONFIG_H) cpplib.h system.h gansidecl.h
proto: config.status protoize$(exeext) unprotoize$(exeext) SYSCALLS.c.X proto: config.status protoize$(exeext) unprotoize$(exeext) SYSCALLS.c.X
protoize$(exeext): protoize.o getopt.o getopt1.o getpwd.o version.o \ protoize$(exeext): protoize.o getopt.o getopt1.o getpwd.o version.o \
pexecute.o choose-temp.o $(LIBDEPS) pexecute.o choose-temp.o mkstemp.o $(LIBDEPS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
protoize.o getopt.o getopt1.o getpwd.o version.o \ protoize.o getopt.o getopt1.o getpwd.o version.o \
pexecute.o choose-temp.o $(LIBS) pexecute.o choose-temp.o mkstemp.o $(LIBS)
unprotoize$(exeext): unprotoize.o getopt.o getopt1.o getpwd.o version.o \ unprotoize$(exeext): unprotoize.o getopt.o getopt1.o getpwd.o version.o \
pexecute.o choose-temp.o $(LIBDEPS) pexecute.o choose-temp.o mkstemp.o $(LIBDEPS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \ $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
unprotoize.o getopt.o getopt1.o getpwd.o version.o \ unprotoize.o getopt.o getopt1.o getpwd.o version.o \
pexecute.o choose-temp.o $(LIBS) pexecute.o choose-temp.o mkstemp.o $(LIBS)
protoize.o: protoize.c getopt.h $(CONFIG_H) system.h protoize.o: protoize.c getopt.h $(CONFIG_H) system.h
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
......
...@@ -110,10 +110,10 @@ choose_temp_base () ...@@ -110,10 +110,10 @@ choose_temp_base ()
char *base = 0; char *base = 0;
char *temp_filename; char *temp_filename;
int len; int len;
int fd;
static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 }; static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 }; static char usrtmp[] = { DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
#ifndef MPW
base = try (getenv ("TMPDIR"), base); base = try (getenv ("TMPDIR"), base);
base = try (getenv ("TMP"), base); base = try (getenv ("TMP"), base);
base = try (getenv ("TEMP"), base); base = try (getenv ("TEMP"), base);
...@@ -130,28 +130,24 @@ choose_temp_base () ...@@ -130,28 +130,24 @@ choose_temp_base ()
if (base == 0) if (base == 0)
base = "."; base = ".";
#else /* MPW */
base = ":";
#endif
len = strlen (base); len = strlen (base);
temp_filename = xmalloc (len + 1 /*DIR_SEPARATOR*/ temp_filename = xmalloc (len + 1 /*DIR_SEPARATOR*/
+ strlen (TEMP_FILE) + 1); + strlen (TEMP_FILE) + 1);
strcpy (temp_filename, base); strcpy (temp_filename, base);
#ifndef MPW
if (len != 0 if (len != 0
&& temp_filename[len-1] != '/' && temp_filename[len-1] != '/'
&& temp_filename[len-1] != DIR_SEPARATOR) && temp_filename[len-1] != DIR_SEPARATOR)
temp_filename[len++] = DIR_SEPARATOR; temp_filename[len++] = DIR_SEPARATOR;
#else /* MPW */
if (temp_filename[len-1] != ':')
temp_filename[len++] = ':';
#endif /* MPW */
strcpy (temp_filename + len, TEMP_FILE); strcpy (temp_filename + len, TEMP_FILE);
mktemp (temp_filename); fd = mkstemp (temp_filename);
if (strlen (temp_filename) == 0) /* If mkstemp failed, then something bad is happening. Maybe we should
issue a message about a possible security attack in progress? */
if (fd == -1)
abort ();
/* Similarly if we can not close the file. */
if (close (fd))
abort (); abort ();
return temp_filename; return temp_filename;
} }
...@@ -1271,6 +1271,9 @@ static int argbuf_length; ...@@ -1271,6 +1271,9 @@ static int argbuf_length;
static int argbuf_index; static int argbuf_index;
/* We want this on by default all the time now. */
#define MKTEMP_EACH_FILE
#ifdef MKTEMP_EACH_FILE #ifdef MKTEMP_EACH_FILE
/* This is the list of suffixes and codes (%g/%u/%U) and the associated /* This is the list of suffixes and codes (%g/%u/%U) and the associated
temp file. */ temp file. */
...@@ -4547,8 +4550,10 @@ main (argc, argv) ...@@ -4547,8 +4550,10 @@ main (argc, argv)
/* Choose directory for temp files. */ /* Choose directory for temp files. */
#ifndef MKTEMP_EACH_FILE
temp_filename = choose_temp_base (); temp_filename = choose_temp_base ();
temp_filename_length = strlen (temp_filename); temp_filename_length = strlen (temp_filename);
#endif
/* Make a table of what switches there are (switches, n_switches). /* Make a table of what switches there are (switches, n_switches).
Make a table of specified input files (infiles, n_infiles). Make a table of specified input files (infiles, n_infiles).
......
/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef IN_GCC
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#else
#include "config.h"
#include "system.h"
/* We need to provide a type for uint64_t. */
#ifdef __GNUC__
typedef unsigned long long uint64_t;
#else
typedef unsigned long uint64_t;
#endif
#ifndef TMP_MAX
#define TMP_MAX 16384
#endif
#endif
/* Generate a unique temporary file name from TEMPLATE.
The last six characters of TEMPLATE must be "XXXXXX";
they are replaced with a string that makes the filename unique.
Returns a file descriptor open on the file for reading and writing. */
int
mkstemp (template)
char *template;
{
static const char letters[62]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static uint64_t value;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
#endif
char *XXXXXX;
size_t len;
int count;
len = strlen (template);
if (len < 6 || strcmp (&template[len - 6], "XXXXXX"))
{
return -1;
}
/* This is where the Xs start. */
XXXXXX = &template[len - 6];
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
__gettimeofday (&tv, NULL);
value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
#else
value += getpid ();
#endif
for (count = 0; count < TMP_MAX; ++count)
{
uint64_t v = value;
int fd;
/* Fill in the random bits. */
XXXXXX[0] = letters[v % 62];
v /= 62;
XXXXXX[1] = letters[v % 62];
v /= 62;
XXXXXX[2] = letters[v % 62];
v /= 62;
XXXXXX[3] = letters[v % 62];
v /= 62;
XXXXXX[4] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600);
if (fd >= 0)
/* The file does not exist. */
return fd;
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
with (module 2^32). */
value += 7777;
}
/* We return the null string if we can't find a unique file name. */
template[0] = '\0';
return -1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment