| joe@invalid.address 2006-07-15, 7:19 pm |
| I'm trying to resolve an apparent conflict between Solaris 9 and
FreeBSD 6.1. After calling localtime() the offsets returned have
opposite signs.
#include <stdio.h>
#include <time.h>
#ifdef sun
#define HAVE_DECL_ALTZONE 1
#else
#define HAVE_STRUCT_TM_TM_GMTOFF 1
#endif
#if HAVE_STRUCT_TM_TM_GMTOFF
inline time_t gmtOffset(const struct tm *t){ return t->tm_gmtoff; }
#elif HAVE_DECL_ALTZONE
extern time_t altzone;
inline time_t gmtOffset(const struct tm *t)
{ return (t->tm_isdst == 1) ? altzone : timezone; }
#endif
int main()
{
struct tm tms;
time_t t = time(0);
tms = *localtime(&t);
printf("tms.tm_gmtoff = %d\n", gmtOffset(&tms));
}
Solaris 9 prints 18000, while FreeBSD prints -18000 (I'm in
US/Central).
POSIX says that the offset component of a TZ variable value is east of
the Prime Meridian when the it has a negative sign, and west of it
when the sign is positive.
I don't see it define the offset received from localtime() though. I'd
expect it to be as defined for a TZ variable setting, but I can see
why negative would make sense in this case too, since localtime() goes
from UTC to local.
FreeBSD doesn't define the POSIX daylight or timezone variables, and
they have a timezone function which returns a character string, so it
doesn't look like FreeBSD is very standard in this regard.
Does POSIX define this somewhere, or is this in the realm of
implementation dependence?
Thanks
Joe
|