blob: f1b3a5a9c22e8d33176c0258969f390a9a082080 (
plain) (
blame)
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
41
42
|
#include <errno.h>
#include <string.h>
#include "nix.h"
#include "util.h"
void _nix_get_string_strdup(const char *str, unsigned n, void *user_data)
{
char **s = user_data;
*s = strndup(str, n);
if (*s == NULL)
print_err("%s", strerror(errno));
}
int _nix_init(nix_c_context **nix_ctx)
{
nix_err nix_ret;
nix_c_context *nc;
int ret = 0;
nc = nix_c_context_create();
if (nix_ctx == NULL) {
print_err("%s", "Failed to create nix context");
return -EPERM;
}
nix_ret = nix_libstore_init(nc);
if (nix_ret != NIX_OK) {
print_err("%s", nix_err_msg(NULL, nc, NULL));
ret = -EPERM;
goto out_free_nc;
}
out_free_nc:
if (ret < 0)
nix_c_context_free(nc);
else
*nix_ctx = nc;
return ret;
}
|