From 887b31ee12704e8c9da3bf4d26801d9236146192 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Tue, 3 Sep 2024 18:58:49 +0530 Subject: nix: init --- src/nix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/nix.c (limited to 'src/nix.c') diff --git a/src/nix.c b/src/nix.c new file mode 100644 index 0000000..f1b3a5a --- /dev/null +++ b/src/nix.c @@ -0,0 +1,42 @@ +#include +#include + +#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; +} -- cgit v1.2.3