# [PATCH] 64-bit fix for date.c.

7 messages from 2009-04-06 to 2009-05-06. Participants: Bernd Ahlers, Jeff King, Junio C Hamano, Tony Finch.
Thread: https://gitlist.dev/t/18750

## Bernd Ahlers, 2009-04-06 17:26

Subject: [PATCH] 64-bit fix for date.c.
Message-ID: <20090406172637.GA17437@jenna.bytemine.net>
URL: https://gitlist.dev/e/20090406172637.GA17437%40jenna.bytemine.net

```
Hello!

This unbreaks the localtime_r call on OpenBSD/sparc64 and removes
the following compiler warning.

"passing arg 1 of `localtime_r' from incompatible pointer type"
---
 date.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/date.c b/date.c
index 1165d30..409a17d 100644
--- a/date.c
+++ b/date.c
@@ -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;
-- 
1.6.2.2

```

## Jeff King, 2009-04-06 19:06

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <20090406190657.GC28120@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090406190657.GC28120%40coredump.intra.peff.net
In-Reply-To: <20090406172637.GA17437@jenna.bytemine.net>

```
On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:

> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>  	struct timeval tv;
> +	time_t time_sec;
> [...]
>  	gettimeofday(&tv, NULL);
> -	localtime_r(&tv.tv_sec, &tm);
> +	time_sec = tv.tv_sec;
> +	localtime_r(&time_sec, &tm);

Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
also, it is actually a "long". So I think this fix makes sense.

-Peff

```

## Bernd Ahlers, 2009-05-04 14:26

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <20090504142614.GE8658@jenna.bytemine.net>
URL: https://gitlist.dev/e/20090504142614.GE8658%40jenna.bytemine.net
In-Reply-To: <20090406190657.GC28120@coredump.intra.peff.net>

```
Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
>On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
>
>> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>>  	struct timeval tv;
>> +	time_t time_sec;
>> [...]
>>  	gettimeofday(&tv, NULL);
>> -	localtime_r(&tv.tv_sec, &tm);
>> +	time_sec = tv.tv_sec;
>> +	localtime_r(&time_sec, &tm);
>
>Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>also, it is actually a "long". So I think this fix makes sense.
>
Okay. So what's the next step to get this committed? :)

Bernd

```

## Jeff King, 2009-05-04 14:31

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <20090504143112.GA14214@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20090504143112.GA14214%40coredump.intra.peff.net
In-Reply-To: <20090504142614.GE8658@jenna.bytemine.net>

```
On Mon, May 04, 2009 at 04:26:14PM +0200, Bernd Ahlers wrote:

> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
> >On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
> >
> >> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
> >>  	struct timeval tv;
> >> +	time_t time_sec;
> >> [...]
> >>  	gettimeofday(&tv, NULL);
> >> -	localtime_r(&tv.tv_sec, &tm);
> >> +	time_sec = tv.tv_sec;
> >> +	localtime_r(&time_sec, &tm);
> >
> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
> >also, it is actually a "long". So I think this fix makes sense.
> >
> Okay. So what's the next step to get this committed? :)

Looks like Junio missed it the first time around, so re-send it to him,
cc'ing the list. And you can add my

  Acked-by: Jeff King <peff@peff.net>

-Peff

```

## Junio C Hamano, 2009-05-06 05:51

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <7vvdoeye1c.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvdoeye1c.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20090504143112.GA14214@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Mon, May 04, 2009 at 04:26:14PM +0200, Bernd Ahlers wrote:
>
>> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
>> >On Mon, Apr 06, 2009 at 07:26:37PM +0200, Bernd Ahlers wrote:
>> >
>> >> @@ -871,13 +871,15 @@ unsigned long approxidate(const char *date)
>> >>  	struct timeval tv;
>> >> +	time_t time_sec;
>> >> [...]
>> >>  	gettimeofday(&tv, NULL);
>> >> -	localtime_r(&tv.tv_sec, &tm);
>> >> +	time_sec = tv.tv_sec;
>> >> +	localtime_r(&time_sec, &tm);
>> >
>> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>> >also, it is actually a "long". So I think this fix makes sense.
>> >
>> Okay. So what's the next step to get this committed? :)
>
> Looks like Junio missed it the first time around, so re-send it to him,
> cc'ing the list. And you can add my
>
>   Acked-by: Jeff King <peff@peff.net>

Thanks.

```

## Tony Finch, 2009-05-06 14:26

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <alpine.LSU.2.00.0905061523300.28199@hermes-2.csi.cam.ac.uk>
URL: https://gitlist.dev/e/alpine.LSU.2.00.0905061523300.28199%40hermes-2.csi.cam.ac.uk
In-Reply-To: <7vvdoeye1c.fsf@alter.siamese.dyndns.org>

```
Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
>
>Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
>also, it is actually a "long". So I think this fix makes sense.

FreeBSD-7 has time_t tv_sec.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.

```

## Jeff King, 2009-05-06 16:49

Subject: Re: [PATCH] 64-bit fix for date.c.
Message-ID: <20090506164900.GA15160@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20090506164900.GA15160%40sigill.intra.peff.net
In-Reply-To: <alpine.LSU.2.00.0905061523300.28199@hermes-2.csi.cam.ac.uk>

```
On Wed, May 06, 2009 at 03:26:36PM +0100, Tony Finch wrote:

> Jeff King [Mon, Apr 06, 2009 at 03:06:58PM -0400] wrote:
> >
> >Hmph. According to POSIX, tv_sec _is_ a time_t. But I see on FreeBSD,
> >also, it is actually a "long". So I think this fix makes sense.
> 
> FreeBSD-7 has time_t tv_sec.

Thanks for the data point (I had looked at FreeBSD 6). I think this fix
still makes sense, though, as it should work on either type (and we
need to support the older platforms, too).

-Peff

```
