| 22 | #include <errno.h> |
| 23 | |
| 24 | int utime_t::invoke_date(const std::string& date_str, utime_t *result) { |
| 25 | char buf[256]; |
| 26 | |
| 27 | SubProcess bin_date("/bin/date", SubProcess::CLOSE, SubProcess::PIPE, |
| 28 | SubProcess::KEEP); |
| 29 | bin_date.add_cmd_args("-d", date_str.c_str(), "+%s %N", NULL); |
| 30 | |
| 31 | int r = bin_date.spawn(); |
| 32 | if (r < 0) return r; |
| 33 | |
| 34 | ssize_t n = safe_read(bin_date.get_stdout(), buf, sizeof(buf)); |
| 35 | |
| 36 | r = bin_date.join(); |
| 37 | if (r || n <= 0) return -EINVAL; |
| 38 | |
| 39 | uint64_t epoch, nsec; |
| 40 | std::istringstream iss(buf); |
| 41 | |
| 42 | iss >> epoch; |
| 43 | iss >> nsec; |
| 44 | |
| 45 | *result = utime_t(epoch, nsec); |
| 46 | |
| 47 | return 0; |
| 48 | } |
nothing calls this directly
no test coverage detected