-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.cpp
More file actions
64 lines (55 loc) · 1.64 KB
/
Copy pathfunctions.cpp
File metadata and controls
64 lines (55 loc) · 1.64 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "functions.hpp"
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <format>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
namespace tsp {
const std::filesystem::path get_tmp() {
auto tmp = std::getenv("TMPDIR");
if (tmp != nullptr) {
return std::filesystem::path{tmp};
}
tmp = std::getenv("PBS_JOBFS");
if (tmp != nullptr) {
return std::filesystem::path{tmp};
} else {
return std::filesystem::path{"/tmp"};
}
};
void die_with_err(std::string_view msg, int status) {
std::cerr << msg << std::endl;
std::cerr << "stat=" << status << std::endl;
std::exit(EXIT_FAILURE);
};
void die_with_err_errno(std::string_view msg, int status) {
std::cerr << msg << std::endl;
std::cerr << "stat=" << status << ", errno=" << errno << std::endl;
std::cerr << strerror(errno) << std::endl;
std::exit(EXIT_FAILURE);
};
int64_t now() {
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
}
std::string format_hh_mm_ss(int64_t us_duration) {
auto hh = us_duration / 3600000000ll;
auto mm = (us_duration / 60000000ll) % 60ll;
auto ss = (us_duration / 1000000ll) % 60ll;
auto us = (us_duration % 1000000ll) / 1000ll;
if (us_duration > 3599999999ll) {
return std::format("{}:{:02}:{:02}.{:03}", hh, mm, ss, us);
} else if (us_duration > 59999999ll) {
return std::format("{}:{:02}.{:03}", mm, ss, us);
} else if (us_duration > 999999ll) {
return std::format("{}.{:03}", ss, us);
} else {
return std::format("0.{:03}", us);
}
}
} // namespace tsp