src: Use gmtime_r instead of gmtime
This commit is contained in:
parent
7b9a8acc22
commit
be4c75a7e9
11
src/util.cc
11
src/util.cc
|
@ -138,9 +138,14 @@ std::string percentDecode
|
||||||
std::string http_date(time_t t)
|
std::string http_date(time_t t)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
tm* tms = gmtime(&t); // returned struct is statically allocated.
|
tm tms;
|
||||||
size_t r = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", tms);
|
|
||||||
return std::string(&buf[0], &buf[r]);
|
if(gmtime_r(&t, &tms) == nullptr) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rv = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", &tms);
|
||||||
|
return std::string(&buf[0], &buf[rv]);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t parse_http_date(const std::string& s)
|
time_t parse_http_date(const std::string& s)
|
||||||
|
|
Loading…
Reference in New Issue