Mailing List Archive

r1785 - trunk/varnish-cache/lib/libvarnish
Author: des
Date: 2007-07-30 15:50:16 +0200 (Mon, 30 Jul 2007)
New Revision: 1785

Modified:
trunk/varnish-cache/lib/libvarnish/time.c
Log:
Use mktime() rather than the unportable timegm(). The downside is that we're
at the mercy of the TZ environment variable.


Modified: trunk/varnish-cache/lib/libvarnish/time.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/time.c 2007-07-30 09:49:05 UTC (rev 1784)
+++ trunk/varnish-cache/lib/libvarnish/time.c 2007-07-30 13:50:16 UTC (rev 1785)
@@ -113,7 +113,7 @@
for (r = fmts; *r != NULL; r++) {
memset(&tm, 0, sizeof tm);
if (strptime(p, *r, &tm) != NULL)
- return(timegm(&tm));
+ return (mktime(&tm));
}
return (0);
}
r1785 - trunk/varnish-cache/lib/libvarnish [ In reply to ]
In message <20070730135017.034F51EC429 at projects.linpro.no>, des at projects.linpro.no writes:
>Author: des
>Date: 2007-07-30 15:50:16 +0200 (Mon, 30 Jul 2007)
>New Revision: 1785
>
>Modified:
> trunk/varnish-cache/lib/libvarnish/time.c
>Log:
>Use mktime() rather than the unportable timegm(). The downside is that we're
>at the mercy of the TZ environment variable.

Which OS doesn't have timegm() ?

Lack of timegm() is so bogus that it should be handled in compat IMO.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
r1785 - trunk/varnish-cache/lib/libvarnish [ In reply to ]
"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
> Which OS doesn't have timegm() ?

timegm() is a BSDism. Solaris doesn't have it, and I suspect other SysV
derivatives (Tru64 etc.) don't either.

> Lack of timegm() is so bogus that it should be handled in compat IMO.

There is no reliable way to emulate it.

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no
r1785 - trunk/varnish-cache/lib/libvarnish [ In reply to ]
In message <87ps2a0yfp.fsf at des.linpro.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= writes:
>"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
>> Which OS doesn't have timegm() ?
>
>timegm() is a BSDism. Solaris doesn't have it, and I suspect other SysV
>derivatives (Tru64 etc.) don't either.
>
>> Lack of timegm() is so bogus that it should be handled in compat IMO.
>
>There is no reliable way to emulate it.

There is, force libc to live in UTC/GMT by setting env variables etc.

But this is a mess, which is why I want us to handle it in compat.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
r1785 - trunk/varnish-cache/lib/libvarnish [ In reply to ]
"Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
> "Dag-Erling Sm?rgrav" <des at linpro.no> writes:
> > "Poul-Henning Kamp" <phk at phk.freebsd.dk> writes:
> > > Lack of timegm() is so bogus that it should be handled in compat IMO.
> > There is no reliable way to emulate it.
> There is, force libc to live in UTC/GMT by setting env variables etc.

First, it wouldn't be thread-safe since the environment is shared
between threads.

Second, setenv() etc. can potentially call malloc(), which is expensive.

Third, setenv() etc. can potentially leak memory.

I know the C / POSIX time-keeping API is rotten, but it's all we have.

DES
--
Dag-Erling Sm?rgrav
Senior Software Developer
Linpro AS - www.linpro.no