src: Use gmtime_r instead of gmtime

This commit is contained in:
Tatsuhiro Tsujikawa 2014-05-14 21:23:21 +09:00
parent 7b9a8acc22
commit be4c75a7e9
1 changed files with 8 additions and 3 deletions

View File

@ -138,9 +138,14 @@ std::string percentDecode
std::string http_date(time_t t)
{
char buf[32];
tm* tms = gmtime(&t); // returned struct is statically allocated.
size_t r = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", tms);
return std::string(&buf[0], &buf[r]);
tm tms;
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)