aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 578b59c..60e12eb 100644
--- a/utils.c
+++ b/utils.c
@@ -140,6 +140,21 @@ void *check_nonnull(void *p, const char *err_msg, ...)
}
//
+// If the given argument is negative, print the error message and exit with
+// failure. Otherwise return the given argument.
+//
+int check_nonnegative(int i, const char *err_msg, ...)
+{
+ if (i < 0) {
+ va_list args;
+ va_start(args, err_msg);
+ verr(EXIT_FAILURE, err_msg, args);
+ va_end(args);
+ }
+ return i;
+}
+
+//
// Case-insensitive memory comparison
//
int memicmp(const void *v1, const void *v2, size_t n)