summaryrefslogtreecommitdiff
path: root/lib/util.c
diff options
context:
space:
mode:
authorLukasz Rzasik <lukasz.rzasik@gmail.com>2016-12-29 15:55:46 -0700
committerBen Pfaff <blp@ovn.org>2017-01-05 08:48:10 -0800
commit1ab39058cc1fbe9b2ce48e784284fd0383d537c5 (patch)
tree9ce73e573c744e65074f920111c8f27d01f312fa /lib/util.c
parent84d0ca5d00fe01b29163236d48fa0f9105687149 (diff)
downloadopenvswitch-1ab39058cc1fbe9b2ce48e784284fd0383d537c5.tar.gz
ovsdb-data: Add support for integer ranges in database commands
Adding / removing a range of integers to a column accepting a set of integers requires enumarating all of the integers. This patch simplifies it by introducing 'range' concept to the database commands. Two integers separated by a hyphen represent an inclusive range. The patch adds positive and negative tests for the new syntax. The patch was tested by 'make check'. Covarage was tested by 'make check-lcov'. Signed-off-by: Lukasz Rzasik <lukasz.rzasik@gmail.com> Suggested-by: <my_ovs_discuss@yahoo.com> Suggested-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib/util.c')
-rw-r--r--lib/util.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/util.c b/lib/util.c
index 4208aa81d..1c06ce0d4 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -640,11 +640,22 @@ str_to_long(const char *s, int base, long *li)
bool
str_to_llong(const char *s, int base, long long *x)
{
- int save_errno = errno;
char *tail;
+ bool ok = str_to_llong_with_tail(s, &tail, base, x);
+ if (*tail != '\0') {
+ *x = 0;
+ return false;
+ }
+ return ok;
+}
+
+bool
+str_to_llong_with_tail(const char *s, char **tail, int base, long long *x)
+{
+ int save_errno = errno;
errno = 0;
- *x = strtoll(s, &tail, base);
- if (errno == EINVAL || errno == ERANGE || tail == s || *tail != '\0') {
+ *x = strtoll(s, tail, base);
+ if (errno == EINVAL || errno == ERANGE || *tail == s) {
errno = save_errno;
*x = 0;
return false;
@@ -668,6 +679,21 @@ str_to_uint(const char *s, int base, unsigned int *u)
}
}
+bool
+str_to_llong_range(const char *s, int base, long long *begin,
+ long long *end)
+{
+ char *tail;
+ if (str_to_llong_with_tail(s, &tail, base, begin)
+ && *tail == '-'
+ && str_to_llong(tail + 1, base, end)) {
+ return true;
+ }
+ *begin = 0;
+ *end = 0;
+ return false;
+}
+
/* Converts floating-point string 's' into a double. If successful, stores
* the double in '*d' and returns true; on failure, stores 0 in '*d' and
* returns false.