aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/utility.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-10-10 17:22:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-11-06 19:32:09 +0300
commitf41599c8e9435f3dfec60b872c2b4ae31177efdd (patch)
tree088f8d9bf906e4a2ed734e034699163c9ccc7306 /libbuild2/utility.cxx
parentac76a4fd2afff48a0d5db84592babe5cabef3a2c (diff)
Add support for test timeouts
Diffstat (limited to 'libbuild2/utility.cxx')
-rw-r--r--libbuild2/utility.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx
index 81f6809..193610f 100644
--- a/libbuild2/utility.cxx
+++ b/libbuild2/utility.cxx
@@ -593,4 +593,22 @@ namespace build2
script::regex::init ();
}
+
+ optional<uint64_t>
+ parse_number (const string& s, uint64_t max_num)
+ {
+ optional<uint64_t> r;
+
+ if (!s.empty ())
+ {
+ const char* b (s.c_str ());
+ char* e (nullptr);
+ uint64_t v (strtoull (b, &e, 10)); // Can't throw.
+
+ if (errno != ERANGE && e == b + s.size () && v <= max_num)
+ r = v;
+ }
+
+ return r;
+ }
}