aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/timeout.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/script/timeout.cxx')
-rw-r--r--libbuild2/script/timeout.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/libbuild2/script/timeout.cxx b/libbuild2/script/timeout.cxx
new file mode 100644
index 0000000..a44e1bb
--- /dev/null
+++ b/libbuild2/script/timeout.cxx
@@ -0,0 +1,26 @@
+// file : libbuild2/script/timeout.cxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#include <libbuild2/script/timeout.hxx>
+
+#include <chrono>
+
+#include <libbuild2/diagnostics.hxx>
+
+using namespace std;
+
+namespace build2
+{
+ optional<duration>
+ parse_timeout (const string& s, const char* what, const location& l)
+ {
+ if (optional<uint64_t> n = parse_number (s))
+ {
+ return *n != 0
+ ? chrono::duration_cast<duration> (chrono::seconds (*n))
+ : optional<duration> ();
+ }
+ else
+ fail (l) << "invalid " << what << " '" << s << "'" << endf;
+ }
+}