Nuke another use of snprintf
This commit is contained in:
parent
1de48a6cb6
commit
96c79ba6b3
1 changed files with 6 additions and 6 deletions
12
src/log.cpp
12
src/log.cpp
|
@ -179,20 +179,20 @@ std::string get_timestamp(const time_t& t, const std::string& format) {
|
|||
return ss.str();
|
||||
}
|
||||
std::string get_timespan(const time_t& t) {
|
||||
char buf[100];
|
||||
std::ostringstream sout;
|
||||
// There doesn't seem to be any library function for this
|
||||
const time_t minutes = t / 60;
|
||||
const time_t days = minutes / 60 / 24;
|
||||
if(t <= 0) {
|
||||
strncpy(buf, "expired", 100);
|
||||
sout << "expired";
|
||||
} else if(minutes == 0) {
|
||||
snprintf(buf, 100, "%ld seconds", t);
|
||||
sout << t << " seconds";
|
||||
} else if(days == 0) {
|
||||
snprintf(buf, 100, "%ld hours, %ld minutes", minutes / 60, minutes % 60);
|
||||
sout << minutes / 60 << " hours, " << minutes % 60 << " minutes";
|
||||
} else {
|
||||
snprintf(buf, 100, "%ld days, %ld hours, %ld minutes", days, (minutes / 60) % 24, minutes % 60);
|
||||
sout << days << " days, " << (minutes / 60) % 24 << " hours, " << minutes % 60 << " minutes";
|
||||
}
|
||||
return buf;
|
||||
return sout.str();
|
||||
}
|
||||
|
||||
static void print_precise_timestamp(std::ostream & out)
|
||||
|
|
Loading…
Add table
Reference in a new issue