diff -Naur tcsh-6.12.00.orig/sh.c tcsh-6.12.00/sh.c --- tcsh-6.14.00/sh.c.orig 2005-03-21 23:26:36 +0200 +++ tcsh-6.14.00/sh.c 2005-04-07 15:24:55 +0300 @@ -737,7 +737,10 @@ shtemp = Strspl(SAVE(strtmp2), doldol); /* For << */ } #else /* !WINNT_NATIVE */ - shtemp = Strspl(STRtmpsh, doldol); /* For << */ + { + char *tmpdir = getenv ("TMPDIR") ?: "/tmp"; + shtemp = Strspl(SAVE(tmpdir), SAVE("/sh.XXXXXX")); /* For << */ + } #endif /* WINNT_NATIVE */ /* diff -Naur tcsh-6.12.00.orig/sh.dol.c tcsh-6.12.00/sh.dol.c --- tcsh-6.14.00/sh.dol.c.orig 2004-12-25 23:15:06 +0200 +++ tcsh-6.14.00/sh.dol.c 2005-04-07 15:40:14 +0300 @@ -1023,45 +1023,27 @@ eChar c; Char *Dv[2]; Char obuf[BUFSIZE + 1], lbuf[BUFSIZE], mbuf[BUFSIZE]; - int ocnt, lcnt, mcnt; + int ocnt, lcnt, mcnt, fd; Char *lbp, *obp, *mbp; Char **vp; int quoted; - char *tmp; -#ifndef WINNT_NATIVE - struct timeval tv; + char *tmp, *dot; -again: -#endif /* WINNT_NATIVE */ tmp = short2str(shtemp); -#ifndef O_CREAT -# define O_CREAT 0 - if (creat(tmp, 0600) < 0) + dot = strrchr(tmp, '.'); + if (!dot) + stderror(ERR_NAME | ERR_NOMATCH); + strcpy(dot, ".XXXXXX"); + + if ((fd = mkstemp(tmp)) < 0) stderror(ERR_SYSTEM, tmp, strerror(errno)); -#endif - (void) close(0); -#ifndef O_TEMPORARY -# define O_TEMPORARY 0 -#endif -#ifndef O_EXCL -# define O_EXCL 0 -#endif - if (open(tmp, O_RDWR|O_CREAT|O_EXCL|O_TEMPORARY|O_LARGEFILE, 0600) == -1) { - int oerrno = errno; -#ifndef WINNT_NATIVE - if (errno == EEXIST) { - if (unlink(tmp) == -1) { - (void) gettimeofday(&tv, NULL); - shtemp = Strspl(STRtmpsh, putn((((int)tv.tv_sec) ^ - ((int)tv.tv_usec) ^ ((int)getpid())) & 0x00ffffff)); - } - goto again; - } -#endif /* WINNT_NATIVE */ - (void) unlink(tmp); - errno = oerrno; - stderror(ERR_SYSTEM, tmp, strerror(errno)); + + if (fd != 0) { + if (dup2(fd, 0) < 0) + stderror(ERR_SYSTEM, "dup2", strerror(errno)); + (void) close(fd); } + (void) unlink(tmp); /* 0 0 inode! */ Dv[0] = term; Dv[1] = NULL;