]> git.ipfire.org Git - thirdparty/git.git/commitdiff
archive-zip.c: switch to reentrant localtime_r
authorDoan Tran Cong Danh <congdanhqx@gmail.com>
Thu, 28 Nov 2019 12:25:04 +0000 (19:25 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 30 Nov 2019 21:50:51 +0000 (13:50 -0800)
Originally, git was intended to be single-thread executable.
`localtime(3)' can be used in such codebase for cleaner code.

Overtime, we're employing multithread in our code base.

Let's phase out `gmtime(3)' in favour of `localtime_r(3)'.

Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-zip.c

index 4d66b5be6e889e865cc998d1c59076e05ebd4712..313c6b9c46848fdaea34af86305f37b9d1b5f16f 100644 (file)
@@ -603,18 +603,18 @@ static void write_zip_trailer(const struct object_id *oid)
 static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
 {
        time_t time;
-       struct tm *t;
+       struct tm tm;
 
        if (date_overflows(*timestamp))
                die(_("timestamp too large for this system: %"PRItime),
                    *timestamp);
        time = (time_t)*timestamp;
-       t = localtime(&time);
+       localtime_r(&time, &tm);
        *timestamp = time;
 
-       *dos_date = t->tm_mday + (t->tm_mon + 1) * 32 +
-                   (t->tm_year + 1900 - 1980) * 512;
-       *dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
+       *dos_date = tm.tm_mday + (tm.tm_mon + 1) * 32 +
+                   (tm.tm_year + 1900 - 1980) * 512;
+       *dos_time = tm.tm_sec / 2 + tm.tm_min * 32 + tm.tm_hour * 2048;
 }
 
 static int archive_zip_config(const char *var, const char *value, void *data)