Subject: Re: gettimeofday()
To: None <port-mac68k@NetBSD.ORG>
From: Christos Zoulas <christos@zoulas.com>
List: port-mac68k
Date: 12/17/1997 12:16:46
In article <Pine.LNX.3.96.971216144451.10904A-100000@globegate.utm.edu> "David A. Gatwood" <marsmail@globegate.utm.edu> writes:
>
>I sent this to a MkLinux list, but there's been really little traffic
>since they switched mail servers and so I figured I'd ask this here, since
>this list seems about a thousand times more active right now.  ;-)  It's
>also just as appropriate/inappropriate, since I tried it on puma with the
>same result.  ;-)
>
>I'm having some trouble with gettimeofday(), specifically the
>timezones....
>
>	struct timezone tz;
>	.
>	.
>	.
>        if (!gettimeofday(NULL, &tz)) {
>		tmhour=tmhour+(ustr[user].gmtbias+((tz.tz_minuteswest)/60));
>                write_user(user,mess);
>                }
>        else {
>                write_user(user,"gettimeofday() failed in tz_set\n\r");
>                tmhour=tmhour+(ustr[user].gmtbias-GLOBAL_BIAS);
>                }
>
>gettimeofday always returns 0 (success), but the minuteswest is also
>always zero.  Not having any experience with this call, I've turned
>HAS_GETTIMEOFDAY off in my code (always have a backup plan)... but I'd
>really like to fix the problem rather than just patch around it....

RTM. the struct tm parameter of gettimeofday is obsolete. use

#include <time.h>

...
	time_t t = time(NULL);
	struct tm *tm = localtime(&t);

	... tm->tm_gmtoff ...

Note, that this will work only on BSD systems.

christos