utils: Make TimevalToString thread-safe
This commit is contained in:
parent
7f9c9c6624
commit
7e86e1ef40
|
@ -22,7 +22,7 @@
|
|||
#include "zm_config.h"
|
||||
#include "zm_logger.h"
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <fcntl.h> /* Definition of AT_* constants */
|
||||
#include <sstream>
|
||||
|
@ -328,16 +328,17 @@ void timespec_diff(struct timespec *start, struct timespec *end, struct timespec
|
|||
}
|
||||
}
|
||||
|
||||
char *timeval_to_string( struct timeval tv ) {
|
||||
time_t nowtime;
|
||||
struct tm *nowtm;
|
||||
static char tmbuf[20], buf[28];
|
||||
std::string TimevalToString(timeval tv) {
|
||||
tm now = {};
|
||||
std::array<char, 26> tm_buf = {};
|
||||
|
||||
nowtime = tv.tv_sec;
|
||||
nowtm = localtime(&nowtime);
|
||||
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
|
||||
snprintf(buf, sizeof buf-1, "%s.%06ld", tmbuf, tv.tv_usec);
|
||||
return buf;
|
||||
localtime_r(&tv.tv_sec, &now);
|
||||
size_t tm_buf_len = strftime(tm_buf.data(), tm_buf.size(), "%Y-%m-%d %H:%M:%S", &now);
|
||||
if (tm_buf_len == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return stringtf("%s.%06ld", tm_buf.data(), tv.tv_usec);
|
||||
}
|
||||
|
||||
std::string UriDecode( const std::string &encoded ) {
|
||||
|
|
|
@ -63,7 +63,7 @@ void hwcaps_detect();
|
|||
extern unsigned int sse_version;
|
||||
extern unsigned int neonversion;
|
||||
|
||||
char *timeval_to_string( struct timeval tv );
|
||||
std::string TimevalToString(timeval tv);
|
||||
std::string UriDecode( const std::string &encoded );
|
||||
void touch( const char *pathname );
|
||||
|
||||
|
|
Loading…
Reference in New Issue