aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-01 00:49:32 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-01 00:49:32 +0100
commit500892b2ae64676d1855d8a357cd39e8a9e7f6c2 (patch)
tree2ab4ea40675d15a66d4a0c4295818f9f83e8c1b1 /src/util.c
parent26a95b35414d0d4b729f3fd5da010debb70b412b (diff)
Add support for $GRAB_TABSIZE
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index d20611f..bf18111 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,10 +1,12 @@
#include <stddef.h>
#include <stdlib.h>
+#include <errno.h>
#include <errors.h>
#include <pcre2.h>
#include "exitcodes.h"
+#include "globals.h"
void
pcre2_bitch_and_die(int ec, const char *fmt)
@@ -21,4 +23,22 @@ pcre2_bitch_and_die(int ec, const char *fmt)
} else
cerr(EXIT_FATAL, fmt, buf);
}
+}
+
+int
+getenv_posnum(const char *ev, int fallback)
+{
+ const char *s = getenv(ev);
+ if (s != nullptr && *s != 0) {
+ const char *endptr;
+ errno = 0;
+ long n = strtol(s, (char **)&endptr, 10);
+ if (errno != 0)
+ warn("strtol: %s:", s);
+ else if (*endptr != 0 || n <= 0)
+ warn("invalid value %s%s%s for %s", lquot, s, rquot, ev);
+ else
+ return (int)n;
+ }
+ return fallback;
} \ No newline at end of file