-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempdir.c
32 lines (23 loc) · 666 Bytes
/
tempdir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define _GNU_SOURCE
#include <stdlib.h>
#include "squashmnt.h"
int sqmnt_create_tmp_dirs(char **upper_dir, char **work_dir) {
const char *tmp_dir = getenv("TMP");
if (!tmp_dir)
tmp_dir = getenv("TEMP");
if (!tmp_dir)
tmp_dir = "/tmp";
asprintf(upper_dir, "%s/squashmnt-upper-XXXXXXXX", tmp_dir);
asprintf(work_dir, "%s/squashmnt-work-XXXXXXX", tmp_dir);
*upper_dir = mkdtemp(*upper_dir);
if (!*upper_dir) {
fprintf(stderr, "Could not create overlayfs' upper dir");
return -1;
}
*work_dir = mkdtemp(*work_dir);
if (!*work_dir) {
fprintf(stderr, "Could not create overlayfs work dir");
return -1;
}
return 0;
}