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:
18
lib/util.c
18
lib/util.c
@@ -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)
|
||||
|
Reference in New Issue
Block a user