commit ba5400a9eec60ae4eb69cff1ee6224b2c8df765c
parent a5b7f756594e4d1e039a594f171d53a8eb851b87
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 17 Feb 2021 14:26:47 -0600
pkg.*: add get_cache_dir
Diffstat:
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/pkg.c b/pkg.c
@@ -92,3 +92,19 @@ pkg_exists(const char *repo, const char *name, char *path)
closedir(pkg);
return 1;
}
+
+#define CACHE_DIR "/.cache/kiss"
+void
+get_cache_dir(char *path)
+{
+ char *home;
+
+ if ((home = getenv("HOME")) == NULL)
+ die("%s: $HOME unset", __func__);
+
+ if (strlen(home) > PATH_LEN - LEN(CACHE_DIR))
+ die("%s: $HOME too long", __func__);
+
+ strcpy(path, home);
+ strcat(path, CACHE_DIR);
+}
diff --git a/pkg.h b/pkg.h
@@ -7,3 +7,4 @@
void pkg_version(char *repo, char *name, char *ver);
int pkg_match(char *repo, char pkgs[][64], const char *pattern);
int pkg_exists(const char *repo, const char *name, char *path);
+void get_cache_dir(char *path);