Skip to content

Commit f697b33

Browse files
berndgitster
authored andcommitted
Work around BSD whose typeof(tv.tv_sec) != time_t
According to POSIX, tv_sec is supposed to be a time_t, but OpenBSD (and FreeBSD, too) defines it to be a long, which triggers a type mismatch when a pointer to it is given to localtime_r(). Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7713e05 commit f697b33

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

date.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
871871
int number = 0;
872872
struct tm tm, now;
873873
struct timeval tv;
874+
time_t time_sec;
874875
char buffer[50];
875876

876877
if (parse_date(date, buffer, sizeof(buffer)) > 0)
877878
return strtoul(buffer, NULL, 10);
878879

879880
gettimeofday(&tv, NULL);
880-
localtime_r(&tv.tv_sec, &tm);
881+
time_sec = tv.tv_sec;
882+
localtime_r(&time_sec, &tm);
881883
now = tm;
882884
for (;;) {
883885
unsigned char c = *date;

0 commit comments

Comments
 (0)