commit 5e7672736a68726a151262675c750b492e5d9fff
parent 35269b8b41fd16b9f2f6a96e153e0a37757d336e
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Sun, 21 Feb 2021 17:50:30 -0600
alt.*: add alt_exists
Diffstat:
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/alt.c b/alt.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "pkg.h"
#include "alt.h"
@@ -43,6 +44,18 @@ to_choice(struct alt_t *alt, char *dest)
strrepl(dest, '/', '>');
}
+int
+alt_exists(struct alt_t *alt)
+{
+ char fname[PATH_LEN], path[PATH_LEN];
+ to_choice(alt, fname);
+
+ if (snprintf(path, PATH_LEN, "%s/%s", KISS_CHOICES, fname) > PATH_LEN)
+ die("%s: path %s too long", KISS_CHOICES, fname);
+
+ return access(path, F_OK);
+}
+
static int
alt_sort(const void *a, const void *b)
{
diff --git a/alt.h b/alt.h
@@ -7,4 +7,5 @@ struct alt_t {
};
void alt_load();
+int alt_exists(struct alt_t *alt);
void alt_owner(char owner[PKG_NAME_MAX], char *path);