From 500892b2ae64676d1855d8a357cd39e8a9e7f6c2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 1 Nov 2024 00:49:32 +0100 Subject: Add support for $GRAB_TABSIZE --- src/util.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util.c') 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 #include +#include #include #include #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 -- cgit v1.2.3