summaryrefslogtreecommitdiffstats
path: root/src/util/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/debug.c')
-rw-r--r--src/util/debug.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/debug.c b/src/util/debug.c
index 98b1853325d..2773b55cc4d 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -21,6 +21,7 @@
* IN THE SOFTWARE.
*/
+#include <errno.h>
#include <string.h>
#include "main/macros.h"
#include "debug.h"
@@ -76,3 +77,22 @@ env_var_as_boolean(const char *var_name, bool default_value)
return default_value;
}
}
+
+/**
+ * Reads an environment variable and interprets its value as a unsigned.
+ */
+unsigned
+env_var_as_unsigned(const char *var_name, unsigned default_value)
+{
+ char *str = getenv(var_name);
+ if (str) {
+ char *end;
+ unsigned long result;
+
+ errno = 0;
+ result = strtoul(str, &end, 0);
+ if (errno == 0 && end != str && *end == '\0')
+ return result;
+ }
+ return default_value;
+}