diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-08 11:26:45 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-08 18:27:21 +0000 |
commit | e09b03e9b131b3a43e4d8e43cc2c667bcb8d0a68 (patch) | |
tree | 6ca99792ace58b83e1d1f8335ef49850f3cbdec9 /wsutil/clopts_common.c | |
parent | 132632bcd96e4ee1ad8e395926af2050545878c4 (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/clopts_common.c')
-rw-r--r-- | wsutil/clopts_common.c | 34 |
1 files changed, 33 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 * |