mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
Use mkstemp(3) to avoid /tmp race.
This commit is contained in:
parent
328b06b929
commit
5204b700b3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=97460
|
@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -136,7 +137,7 @@ main(int argc, char *argv[])
|
||||||
static void
|
static void
|
||||||
writeIfChanged(char *fname, int lang, int orConsts)
|
writeIfChanged(char *fname, int lang, int orConsts)
|
||||||
{
|
{
|
||||||
char tmpname[32];
|
char tmpname[] = _PATH_TMP"/gencat.XXXXXX";
|
||||||
char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
|
char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
|
||||||
int fd, tfd;
|
int fd, tfd;
|
||||||
int diff = FALSE;
|
int diff = FALSE;
|
||||||
|
@ -153,9 +154,8 @@ writeIfChanged(char *fname, int lang, int orConsts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it does exist, create a temp file for now */
|
/* If it does exist, create a temp file for now */
|
||||||
sprintf(tmpname, "/tmp/gencat.%d", (int) getpid());
|
if ((tfd = mkstemp(tmpname)) < 0)
|
||||||
if ((tfd = open(tmpname, O_RDWR|O_CREAT, 0666)) < 0)
|
err(1, "mkstemp");
|
||||||
errx(1, "unable to open temporary file: %s", tmpname);
|
|
||||||
unlink(tmpname);
|
unlink(tmpname);
|
||||||
|
|
||||||
/* Write to the temp file and rewind */
|
/* Write to the temp file and rewind */
|
||||||
|
|
Loading…
Reference in a new issue