aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/timeout.cxx
blob: 63cc61ad7ee44afe3ad339c0328755a138a62a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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 char* prefix,
                 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) << prefix << "invalid " << what << " '" << s << "'" << endf;
  }
}