2 * Handle command-line arguments common to various programs
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "clopts_common.h"
18 #include <wsutil/strtoi.h>
19 #include <wsutil/cmdarg_err.h>
22 get_natural_int(const char *string
, const char *name
)
26 if (!ws_strtoi32(string
, NULL
, &number
)) {
27 if (errno
== EINVAL
) {
28 cmdarg_err("The specified %s \"%s\" isn't a decimal number", name
, string
);
32 cmdarg_err("The specified %s \"%s\" is a negative number", name
, string
);
35 cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
36 name
, string
, number
);
40 cmdarg_err("The specified %s \"%s\" is a negative number", name
, string
);
47 get_positive_int(const char *string
, const char *name
)
51 number
= get_natural_int(string
, name
);
54 cmdarg_err("The specified %s is zero", name
);
62 get_uint32(const char *string
, const char *name
)
66 if (!ws_strtou32(string
, NULL
, &number
)) {
67 if (errno
== EINVAL
) {
68 cmdarg_err("The specified %s \"%s\" isn't a decimal number", name
, string
);
71 cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
72 name
, string
, number
);
79 get_nonzero_uint32(const char *string
, const char *name
)
83 number
= get_uint32(string
, name
);
86 cmdarg_err("The specified %s is zero", name
);
94 get_uint64(const char *string
, const char *name
)
98 if (!ws_strtou64(string
, NULL
, &number
)) {
99 if (errno
== EINVAL
) {
100 cmdarg_err("The specified %s \"%s\" isn't a decimal number", name
, string
);
103 cmdarg_err("The specified %s \"%s\" is too large (greater than %" PRIu64
")",
104 name
, string
, number
);
111 get_nonzero_uint64(const char *string
, const char *name
)
115 number
= get_uint64(string
, name
);
118 cmdarg_err("The specified %s is zero", name
);
126 get_positive_double(const char *string
, const char *name
)
128 double number
= g_ascii_strtod(string
, NULL
);
130 if (errno
== EINVAL
) {
131 cmdarg_err("The specified %s \"%s\" isn't a floating point number", name
, string
);
135 cmdarg_err("The specified %s \"%s\" is a negative number", name
, string
);