mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-27 16:50:58 +01:00
Use the new gettempfile() function.
This commit is contained in:
parent
65729f5570
commit
3ccc3e4bdc
4 changed files with 9 additions and 16 deletions
|
|
@ -1971,8 +1971,7 @@ zftp_open(char *name, char **args, int flags)
|
|||
* However, it is closed whenever there are no connections open.
|
||||
*/
|
||||
if (zfstatfd == -1) {
|
||||
fname = gettempname(NULL, 1);
|
||||
zfstatfd = open(fname, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
zfstatfd = gettempfile(NULL, 1, &fname);
|
||||
DPUTS(zfstatfd == -1, "zfstatfd not created");
|
||||
#if defined(F_SETFD) && defined(FD_CLOEXEC)
|
||||
/* If the shell execs a program, we don't want this fd left open. */
|
||||
|
|
|
|||
|
|
@ -1445,10 +1445,8 @@ bin_fc(char *nam, char **argv, Options ops, int func)
|
|||
char *fil;
|
||||
|
||||
retval = 1;
|
||||
fil = gettempname(NULL, 1);
|
||||
if (((tempfd = open(fil, O_WRONLY | O_CREAT | O_EXCL | O_NOCTTY, 0600))
|
||||
== -1) ||
|
||||
((out = fdopen(tempfd, "w")) == NULL)) {
|
||||
if ((tempfd = gettempfile(NULL, 1, &fil)) < 0
|
||||
|| ((out = fdopen(tempfd, "w")) == NULL)) {
|
||||
unqueue_signals();
|
||||
zwarnnam("fc", "can't open temp file: %e", NULL, errno);
|
||||
} else {
|
||||
|
|
@ -3535,8 +3533,8 @@ bin_print(char *name, char **args, Options ops, int func)
|
|||
zwarnnam(name, "open_memstream failed", NULL, 0);
|
||||
#else
|
||||
int tempfd;
|
||||
char *tmpf = gettempname(NULL, 1);
|
||||
if ((tempfd = open(tmpf, O_RDWR|O_CREAT|O_EXCL, 0644)) < 0
|
||||
char *tmpf;
|
||||
if ((tempfd = gettempfile(NULL, 1, &tmpf)) < 0
|
||||
|| (fout = fdopen(tempfd, "w+")) == NULL)
|
||||
zwarnnam(name, "can't open temp file: %e", NULL, errno);
|
||||
unlink(tmpf);
|
||||
|
|
|
|||
|
|
@ -2801,8 +2801,7 @@ getherestr(struct redir *fn)
|
|||
untokenize(t);
|
||||
unmetafy(t, &len);
|
||||
t[len++] = '\n';
|
||||
s = gettempname(NULL, 1);
|
||||
if (!s || (fd = open(s, O_CREAT|O_WRONLY|O_EXCL|O_NOCTTY, 0600)) == -1)
|
||||
if ((fd = gettempfile(NULL, 1, &s)) < 0)
|
||||
return -1;
|
||||
write(fd, t, len);
|
||||
close(fd);
|
||||
|
|
@ -2975,11 +2974,9 @@ getoutputfile(char *cmd)
|
|||
return NULL;
|
||||
if (!(prog = parsecmd(cmd)))
|
||||
return NULL;
|
||||
if (!(nam = gettempname(NULL, 1)))
|
||||
if (!(nam = gettempname(NULL, 0)))
|
||||
return NULL;
|
||||
|
||||
nam = ztrdup(nam);
|
||||
|
||||
if (!jobtab[thisjob].filelist)
|
||||
jobtab[thisjob].filelist = znewlinklist();
|
||||
zaddlinknode(jobtab[thisjob].filelist, nam);
|
||||
|
|
|
|||
|
|
@ -2137,8 +2137,7 @@ lockhistfile(char *fn, int keep_trying)
|
|||
|
||||
lockfile = bicat(unmeta(fn), ".LOCK");
|
||||
#ifdef HAVE_LINK
|
||||
tmpfile = gettempname(fn, 0);
|
||||
if ((fd = open(tmpfile, O_WRONLY|O_CREAT|O_EXCL, 0644)) >= 0) {
|
||||
if ((fd = gettempfile(fn, 0, &tmpfile)) >= 0) {
|
||||
FILE *out = fdopen(fd, "w");
|
||||
if (out) {
|
||||
fprintf(out, "%ld %s\n", (long)getpid(), getsparam("HOST"));
|
||||
|
|
@ -2163,8 +2162,8 @@ lockhistfile(char *fn, int keep_trying)
|
|||
break;
|
||||
}
|
||||
unlink(tmpfile);
|
||||
}
|
||||
free(tmpfile);
|
||||
}
|
||||
#else /* not HAVE_LINK */
|
||||
while ((fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
|
||||
if (errno != EEXIST || !keep_trying)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue