2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

util: Make hexits_value() support 64-bit integers too.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
This commit is contained in:
Ben Pfaff
2014-09-30 12:45:50 -07:00
parent c8058af786
commit 0429d9599c
4 changed files with 17 additions and 17 deletions

View File

@@ -701,29 +701,25 @@ hexit_value(int c)
}
/* Returns the integer value of the 'n' hexadecimal digits starting at 's', or
* UINT_MAX if one of those "digits" is not really a hex digit. If 'ok' is
* nonnull, '*ok' is set to true if the conversion succeeds or to false if a
* non-hex digit is detected. */
unsigned int
* UINTMAX_MAX if one of those "digits" is not really a hex digit. Sets '*ok'
* to true if the conversion succeeds or to false if a non-hex digit is
* detected. */
uintmax_t
hexits_value(const char *s, size_t n, bool *ok)
{
unsigned int value;
uintmax_t value;
size_t i;
value = 0;
for (i = 0; i < n; i++) {
int hexit = hexit_value(s[i]);
if (hexit < 0) {
if (ok) {
*ok = false;
}
return UINT_MAX;
*ok = false;
return UINTMAX_MAX;
}
value = (value << 4) + hexit;
}
if (ok) {
*ok = true;
}
*ok = true;
return value;
}