2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

util: Introduce str_to_ullong() helper function.

Will be used to convert strings to unsigned long long.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jan Scheurich <jan.scheurich@ericsson.com>
This commit is contained in:
Ilya Maximets
2017-11-29 13:50:44 +03:00
committed by Ben Pfaff
parent 65dca9eb09
commit c24b3458b6
2 changed files with 19 additions and 0 deletions

View File

@@ -765,6 +765,24 @@ str_to_uint(const char *s, int base, unsigned int *u)
}
}
bool
str_to_ullong(const char *s, int base, unsigned long long *x)
{
int save_errno = errno;
char *tail;
errno = 0;
*x = strtoull(s, &tail, base);
if (errno == EINVAL || errno == ERANGE || tail == s || *tail != '\0') {
errno = save_errno;
*x = 0;
return false;
} else {
errno = save_errno;
return true;
}
}
bool
str_to_llong_range(const char *s, int base, long long *begin,
long long *end)