27 if ((prog = strrchr(path,
'/')))
34 template <
class Duration>
35 constexpr std::chrono::hours
36 toHours(
const Duration &d)
38 return std::chrono::duration_cast<std::chrono::hours>(d);
42 template <
class Duration>
43 constexpr std::chrono::minutes
44 toMinutes(
const Duration &d)
46 return std::chrono::duration_cast<std::chrono::minutes>(d);
50 template <
class Duration>
51 constexpr std::chrono::seconds
52 toSeconds(
const Duration &d)
54 return std::chrono::duration_cast<std::chrono::seconds>(d);
58 template <
class Duration>
59 constexpr std::chrono::milliseconds
60 toMilliseconds(
const Duration &d)
62 return std::chrono::duration_cast<std::chrono::milliseconds>(d);
66 template <
class Duration>
67 constexpr std::chrono::microseconds
68 toMicroseconds(
const Duration &d)
70 return std::chrono::duration_cast<std::chrono::microseconds>(d);
74 template <
class Duration>
75 constexpr std::chrono::nanoseconds
76 toNanoseconds(
const Duration &d)
78 return std::chrono::duration_cast<std::chrono::nanoseconds>(d);
83 template <
typename Rep,
typename Period>
88 static_cast<decltype(timespec::tv_sec)
>(::toSeconds(d).count()),
89 static_cast<decltype(timespec::tv_nsec)
>(::toNanoseconds(d - ::toSeconds(d)).count())};
92 static void printTm(std::ostream &os, time_t sec,
char origfill)
98 const std::ios::fmtflags oldflags = os.flags(std::ios::fixed | std::ios::dec);
99 const char oldfill = os.fill(
'0');
101 if (origfill ==
'\0')
103 os << std::setw(2) << ptm.tm_hour
104 << std::setw(2) << ptm.tm_min
105 << std::setw(2) << ptm.tm_sec;
110 if (origfill ==
'-' || origfill ==
'.')
113 os << std::setw(2) << ptm.tm_hour
115 << std::setw(2) << ptm.tm_min
117 << std::setw(2) << ptm.tm_sec;
124 extern std::ostream &
operator<<(std::ostream &os,
const tm &_t)
126 const std::ios::fmtflags oldflags = os.flags(std::ios::fixed | std::ios::dec);
127 const char oldfill = os.fill(
'0');
130 os << std::setw(4) << _t.tm_year + 1900 <<
'-' 131 << std::setw(2) << _t.tm_mon + 1 <<
'-' 132 << std::setw(2) << _t.tm_mday <<
' ' 133 << std::setw(2) << _t.tm_hour <<
':' 134 << std::setw(2) << _t.tm_min <<
':' 135 << std::setw(2) << _t.tm_sec;
145 extern std::ostream &
operator<<(std::ostream &os,
const timespec &_t)
147 const std::ios::fmtflags oldflags = os.flags(std::ios::fixed | std::ios::right);
148 const char oldfill = os.fill(
' ');
150 if (os.flags() & std::ios::scientific)
153 printTm(os, _t.tv_sec, oldfill);
155 os <<
'.' << std::setfill(
'0') << std::setw(9) << _t.tv_nsec;
169 template <
typename Rep,
typename Period>
170 inline std::ostream &
171 operator<<(std::ostream &os, const std::chrono::duration<Rep, Period> &d)
184 template <
typename Rep>
186 operator<<(std::ostream &os, const std::chrono::duration<Rep, std::ratio<1>> &d)
189 if (os.flags() & std::ios::showbase)
190 os << (os.flags() & std::ios::skipws ?
"s" :
" s");
201 template <
typename Rep>
203 operator<<(std::ostream &os, const std::chrono::duration<Rep, std::milli> &d)
206 if (os.flags() & std::ios::showbase)
207 os << (os.flags() & std::ios::skipws ?
"ms" :
" ms");
218 template <
typename Rep>
220 operator<<(std::ostream &os, const std::chrono::duration<Rep, std::micro> &d)
223 if (os.flags() & std::ios::showbase)
224 os << (os.flags() & std::ios::skipws ?
"µs" :
" µs");
235 template <
typename Rep>
237 operator<<(std::ostream &os, const std::chrono::duration<Rep, std::nano> &d)
240 if (os.flags() & std::ios::showbase)
241 os << (os.flags() & std::ios::skipws ?
"ns" :
" ns");
256 template <
typename Clock,
typename Duration>
257 inline std::ostream &
258 operator<<(std::ostream &os, const std::chrono::time_point<Clock, Duration> &tp)
260 const auto d = tp.time_since_epoch();
262 if (os.flags() & std::ios::scientific)
270 extern int mkdirPath(
const std::string &_dirpath,
int _mode = S_IRWXU | S_IRWXG | S_IRWXO)
272 if (_dirpath.empty())
284 p.resize(_dirpath.size() + 1);
285 std::vector<char>::iterator pend = std::copy(_dirpath.begin(), _dirpath.end(), p.begin());
289 char *
const pstart = &p[0];
295 if (*ps ==
'/' || *ps ==
'\0')
301 if (stat(pstart, &sbuf) == -1)
303 if (mkdir(pstart, _mode) == -1)
308 else if (!S_ISDIR(sbuf.st_mode))
const char * progname(const char *path)
Get the program name, similar to basename.
Definition: clientUtil.hh:23
std::ostream & operator<<(std::ostream &os, const timespec &_t)
Output operator for struct timespec as used e.g. by pselect or nanosleep.
Definition: clientUtil.hh:145
timespec toTimespec(const std::chrono::duration< Rep, Period > &d)
Convert a chrono duration into a POSIX timespec.
Definition: clientUtil.hh:85