aboutsummaryrefslogtreecommitdiff
path: root/src/paths.c
blob: 59f601fa77f17a7bbdd122ef7a98d83b0c16930f (plain)
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
32
33
34
35
36
37
38
39
40
#include "paths.h"
#include "log.h"

#include "errno.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sys/stat.h"
#include "unistd.h"

char template[] = "/var/tmp/pow/XXXXXX";

int pow_create_dir_for_package(char **path) {
  if (mkdir("/var/tmp/pow", 0700)) {
    if (errno != EEXIST) {
      pow_log_error("failed to create temp dir\n");

      return 1;
    }
  }

  char *new_path = malloc(strlen(template) + 1);

  if (!new_path) {
    return 1;
  }

  strcpy(new_path, template);

  if (!mkdtemp(new_path)) {
    pow_log_error("failed to make dir\n");
    free(new_path);

    return 1;
  }

  *path = new_path;

  return 0;
}