Skip to content

Commit b5ab03b

Browse files
sgngitster
authored andcommitted
archive-zip.c: switch to reentrant localtime_r
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccd4694 commit b5ab03b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

archive-zip.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,18 @@ static void write_zip_trailer(const struct object_id *oid)
603603
static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
604604
{
605605
time_t time;
606-
struct tm *t;
606+
struct tm tm;
607607

608608
if (date_overflows(*timestamp))
609609
die(_("timestamp too large for this system: %"PRItime),
610610
*timestamp);
611611
time = (time_t)*timestamp;
612-
t = localtime(&time);
612+
localtime_r(&time, &tm);
613613
*timestamp = time;
614614

615-
*dos_date = t->tm_mday + (t->tm_mon + 1) * 32 +
616-
(t->tm_year + 1900 - 1980) * 512;
617-
*dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
615+
*dos_date = tm.tm_mday + (tm.tm_mon + 1) * 32 +
616+
(tm.tm_year + 1900 - 1980) * 512;
617+
*dos_time = tm.tm_sec / 2 + tm.tm_min * 32 + tm.tm_hour * 2048;
618618
}
619619

620620
static int archive_zip_config(const char *var, const char *value, void *data)

0 commit comments

Comments
 (0)