diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-04-09 16:06:17 -0700 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-04-09 16:06:17 -0700 |
commit | 14eb94eefa8b3d84ca4db006f7ae4f2347cd2238 (patch) | |
tree | ac4ff5b3a3b66402414c410eef45140eda0ff3ca /src | |
parent | 8416c9adccc6ee6d5aeb09153db7315622bf12a1 (diff) | |
download | libgit2-14eb94eefa8b3d84ca4db006f7ae4f2347cd2238.tar.gz |
Fix `gmtime` issues in Win32
Diffstat (limited to 'src')
-rw-r--r-- | src/signature.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/signature.c b/src/signature.c index c5b175cf3..15753a7e6 100644 --- a/src/signature.c +++ b/src/signature.c @@ -68,18 +68,32 @@ git_signature *git_signature_dup(const git_signature *sig) git_signature *git_signature_now(const char *name, const char *email) { time_t now; - struct tm utc_tm, local_tm; int offset; + struct tm *utc_tm, *local_tm; - time(&now); +#ifndef GIT_WIN32 + struct tm _utc, _local; +#endif - gmtime_r(&now, &utc_tm); - localtime_r(&now, &local_tm); + time(&now); - offset = mktime(&local_tm) - mktime(&utc_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 /= 60; + /* mktime takes care of setting tm_isdst correctly */ - if (local_tm.tm_isdst) + if (local_tm->tm_isdst) offset += 60; return git_signature_new(name, email, now, offset); |