diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-09-03 18:58:49 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-09-03 18:58:49 +0530 |
commit | 887b31ee12704e8c9da3bf4d26801d9236146192 (patch) | |
tree | 210d036978bad153f5e8ee46c14c4fc902ce7d37 /src/nix.c | |
parent | a1eb8e06c42bf15e916a83180fc0d62c5a86fd37 (diff) |
nix: init
Diffstat (limited to 'src/nix.c')
-rw-r--r-- | src/nix.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 <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; +} |