commit 8d4feaaaaebb921e2901bff67e90592983c548ce
parent 042b53a2a18f40c146174333b1e8dc16480684f9
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 17 Feb 2021 10:46:02 -0600
pkg.*: add pkg_version
Diffstat:
A | pkg.c | | | 27 | +++++++++++++++++++++++++++ |
A | pkg.h | | | 4 | ++++ |
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/pkg.c b/pkg.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "pkg.h"
+#include "util.h"
+
+void
+pkg_version(char *repo, char *name, char *ver)
+{
+ char path[strlen(repo) + strlen(name) + 10];
+ FILE *vfile;
+
+ strcpy(path, repo);
+ strcat(path, "/");
+ strcat(path, name);
+ strcat(path, "/version");
+
+ if ((vfile = fopen(path, "r")) == NULL)
+ die("%s: failed to open version file for %s", __func__, name);
+
+ if (fgets(ver, PKG_VERSION_MAX, vfile) == NULL) {
+ fclose(vfile);
+ die("%s: failed to read version file for %s", __func__, name);
+ }
+
+ fclose(vfile);
+}
diff --git a/pkg.h b/pkg.h
@@ -0,0 +1,4 @@
+#define KISS_INSTALLED "/var/db/kiss/installed"
+#define PKG_VERSION_MAX 256
+
+void pkg_version(char *repo, char *name, char *ver);