From e09b03e9b131b3a43e4d8e43cc2c667bcb8d0a68 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 8 Sep 2016 11:26:45 -0700 Subject: 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 --- wsutil/clopts_common.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'wsutil/clopts_common.c') 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 * -- cgit v1.2.1