Skip to content

Commit

Permalink
Work around BSD whose typeof(tv.tv_sec) != time_t
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bernd authored and gitster committed May 6, 2009
1 parent 7713e05 commit f697b33
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion date.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
int number = 0;
struct tm tm, now;
struct timeval tv;
time_t time_sec;
char buffer[50];

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

gettimeofday(&tv, NULL);
localtime_r(&tv.tv_sec, &tm);
time_sec = tv.tv_sec;
localtime_r(&time_sec, &tm);
now = tm;
for (;;) {
unsigned char c = *date;
Expand Down

0 comments on commit f697b33

Please sign in to comment.