mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 13:25:18 +00:00
Fix gmtime
issues in Win32
This commit is contained in:
parent
8416c9adcc
commit
14eb94eefa
@ -68,18 +68,32 @@ git_signature *git_signature_dup(const git_signature *sig)
|
|||||||
git_signature *git_signature_now(const char *name, const char *email)
|
git_signature *git_signature_now(const char *name, const char *email)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
struct tm utc_tm, local_tm;
|
|
||||||
int offset;
|
int offset;
|
||||||
|
struct tm *utc_tm, *local_tm;
|
||||||
|
|
||||||
|
#ifndef GIT_WIN32
|
||||||
|
struct tm _utc, _local;
|
||||||
|
#endif
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
|
|
||||||
gmtime_r(&now, &utc_tm);
|
/**
|
||||||
localtime_r(&now, &local_tm);
|
* On Win32, `gmtime_r` doesn't exist but
|
||||||
|
* `gmtime` is threadsafe, so we can use that
|
||||||
|
*/
|
||||||
|
#ifdef GIT_WIN32
|
||||||
|
utc_tm = gmtime(&now);
|
||||||
|
local_tm = localtime(&now);
|
||||||
|
#else
|
||||||
|
utc_tm = gmtime_r(&now, &_utc);
|
||||||
|
local_tm = localtime_r(&now, &_local);
|
||||||
|
#endif
|
||||||
|
|
||||||
offset = mktime(&local_tm) - mktime(&utc_tm);
|
offset = mktime(local_tm) - mktime(utc_tm);
|
||||||
offset /= 60;
|
offset /= 60;
|
||||||
|
|
||||||
/* mktime takes care of setting tm_isdst correctly */
|
/* mktime takes care of setting tm_isdst correctly */
|
||||||
if (local_tm.tm_isdst)
|
if (local_tm->tm_isdst)
|
||||||
offset += 60;
|
offset += 60;
|
||||||
|
|
||||||
return git_signature_new(name, email, now, offset);
|
return git_signature_new(name, email, now, offset);
|
||||||
|
Loading…
Reference in New Issue
Block a user