summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloe M <chloe@faracom.org>2026-08-16 01:36:10 -0500
committerChloe M <chloe@faracom.org>2026-08-16 01:36:10 -0500
commit0d185faaed5db14bf3c9d42d92337c9d749021c7 (patch)
treee07b22d39a3a724e44daeafc4b536fb0e8c1407e
parent6154c691de032bd5dc8fe30c6d04950b1a68be67 (diff)
tools: Add checkenv tool for verifying if ENVs are set
Signed-off-by: Chloe M <chloe@faracom.org>
-rw-r--r--build.sh1
-rw-r--r--checkenv/.bop/posthook.sh1
-rw-r--r--checkenv/checkenv.c66
3 files changed, 68 insertions, 0 deletions
diff --git a/build.sh b/build.sh
index 0d7206c..c86dc19 100644
--- a/build.sh
+++ b/build.sh
@@ -3,3 +3,4 @@
mkdir -p bin/
BOP_BUILD=levd bop build
BOP_BUILD=newpass bop build
+BOP_BUILD=checkenv bop build
diff --git a/checkenv/.bop/posthook.sh b/checkenv/.bop/posthook.sh
new file mode 100644
index 0000000..67caec9
--- /dev/null
+++ b/checkenv/.bop/posthook.sh
@@ -0,0 +1 @@
+clang checkenv/*.o -o bin/checkenv
diff --git a/checkenv/checkenv.c b/checkenv/checkenv.c
new file mode 100644
index 0000000..d2d6c57
--- /dev/null
+++ b/checkenv/checkenv.c
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void
+help(void)
+{
+ printf("usage: ./checkenv <ENV>:<...>:<...>\n");
+ printf("[-h] Display this help menu\n");
+}
+
+static int
+check_envs(const char *envlist)
+{
+ char *p, *tok;
+ char *env;
+
+ p = strdup(envlist);
+ if (p == NULL) {
+ printf("fatal: out of memory\n");
+ return -1;
+ }
+
+ tok = strtok(p, ":");
+ while (tok != NULL) {
+ if ((env = getenv(tok)) == NULL) {
+ printf("env '%s' not set\n", tok);
+ return -1;
+ }
+ tok = strtok(NULL, ":");
+ }
+
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int opt;
+ char *envlist;
+ int error;
+
+ if (argc < 2) {
+ printf("fatal: too few arguments\n");
+ help();
+ return -1;
+ }
+
+ while ((opt = getopt(argc, argv, "h")) != -1) {
+ switch (opt) {
+ case 'h':
+ help();
+ return -1;
+ }
+ }
+
+ while (optind < argc) {
+ envlist = argv[optind++];
+ if ((error = check_envs(envlist)) < 0) {
+ return error;
+ }
+ }
+
+ return 0;
+}