]> git.scottworley.com Git - overonion/blame - temp_file.c
Refuse to re-use keys
[overonion] / temp_file.c
CommitLineData
2377b838
SW
1#define _GNU_SOURCE
2
3#include "temp_file.h"
4
5#include <err.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <sysexits.h>
9
10void make_temporary_file(char** temp_filename, FILE** temp_file) {
11 char* TMPDIR = getenv("TMPDIR");
12 if (TMPDIR == NULL) {
13 TMPDIR = "/tmp";
14 }
15 if (asprintf(temp_filename, "%s/reverse.XXXXXX", TMPDIR) == -1) {
16 errx(EX_OSERR, "Could not assemble temporary filename");
17 }
18 int fd = mkstemp(*temp_filename);
19 if (fd == -1) err(EX_IOERR, "Could not make a temporary file");
20 *temp_file = fdopen(fd, "w");
21 if (*temp_file == NULL) err(EX_IOERR, "Could not open temporary file");
22}