Improve temporary file handling
Obtained from: OpenBSD
This commit is contained in:
parent
d07a0d1d4c
commit
dd0208b307
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178973
@ -100,6 +100,7 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
int fdesc;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "-cv")) != -1)
|
while ((c = getopt(argc, argv, "-cv")) != -1)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -122,8 +123,16 @@ main(int argc, char *argv[])
|
|||||||
signal(SIGINT, onintr);
|
signal(SIGINT, onintr);
|
||||||
if (cflg || (argc == 0 && !readstd))
|
if (cflg || (argc == 0 && !readstd))
|
||||||
inithash();
|
inithash();
|
||||||
else
|
else {
|
||||||
strings = mktemp(strdup(_PATH_TMP));
|
strings = strdup(_PATH_TMP);
|
||||||
|
if (strings == NULL)
|
||||||
|
err(1, "strdup() failed");
|
||||||
|
fdesc = mkstemp(strings);
|
||||||
|
if (fdesc == -1)
|
||||||
|
err(1, "Unable to create temporary file");
|
||||||
|
close(fdesc);
|
||||||
|
}
|
||||||
|
|
||||||
while (readstd || argc > 0) {
|
while (readstd || argc > 0) {
|
||||||
if (freopen("x.c", "w", stdout) == NULL)
|
if (freopen("x.c", "w", stdout) == NULL)
|
||||||
err(1, "x.c");
|
err(1, "x.c");
|
||||||
|
Loading…
Reference in New Issue
Block a user