aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-09-08 11:26:45 -0700
committerGuy Harris <guy@alum.mit.edu>2016-09-08 18:27:21 +0000
commite09b03e9b131b3a43e4d8e43cc2c667bcb8d0a68 (patch)
tree6ca99792ace58b83e1d1f8335ef49850f3cbdec9 /wsutil
parent132632bcd96e4ee1ad8e395926af2050545878c4 (diff)
Add get_ routines to get a guint32, and use them.
By analogy to get_natural_int() and get_positive_int(), add routines to get a guint32 and to get a non-zero guint32, doing all the necessary error checks, and use it. Change-Id: I65a9ac8a3d136886df3588806ae7af5bdc7b8cb6 Reviewed-on: https://code.wireshark.org/review/17586 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/clopts_common.c34
-rw-r--r--wsutil/clopts_common.h6
2 files changed, 39 insertions, 1 deletions
diff --git a/wsutil/clopts_common.c b/wsutil/clopts_common.c
index 1967014c82..78763328d5 100644
--- a/wsutil/clopts_common.c
+++ b/wsutil/clopts_common.c
@@ -56,7 +56,6 @@ get_natural_int(const char *string, const char *name)
return (int)number;
}
-
int
get_positive_int(const char *string, const char *name)
{
@@ -72,6 +71,39 @@ get_positive_int(const char *string, const char *name)
return number;
}
+guint32
+get_guint32(const char *string, const char *name)
+{
+ const char *end;
+ guint32 number;
+
+ if (!ws_strtou32(string, &end, &number)) {
+ if (errno == EINVAL || *end != '\0') {
+ cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string);
+ exit(1);
+ }
+ cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
+ name, string, number);
+ exit(1);
+ }
+ return number;
+}
+
+guint32
+get_nonzero_guint32(const char *string, const char *name)
+{
+ guint32 number;
+
+ number = get_guint32(string, name);
+
+ if (number == 0) {
+ cmdarg_err("The specified %s is zero", name);
+ exit(1);
+ }
+
+ return number;
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
diff --git a/wsutil/clopts_common.h b/wsutil/clopts_common.h
index c409e8957a..ca0bb7bc33 100644
--- a/wsutil/clopts_common.h
+++ b/wsutil/clopts_common.h
@@ -35,6 +35,12 @@ get_natural_int(const char *string, const char *name);
WS_DLL_PUBLIC int
get_positive_int(const char *string, const char *name);
+WS_DLL_PUBLIC guint32
+get_guint32(const char *string, const char *name);
+
+WS_DLL_PUBLIC guint32
+get_nonzero_guint32(const char *string, const char *name);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */