1 | --- pl-tai.c.orig Thu Aug 10 16:52:22 2006 |
---|
2 | +++ pl-tai.c Thu Aug 10 16:56:19 2006 |
---|
3 | @@ -22,14 +22,6 @@ |
---|
4 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
5 | */ |
---|
6 | |
---|
7 | -/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
---|
8 | -Somehow, MacOS X defines timezone() as a function. Using the #define |
---|
9 | -__DARWIN_UNIX03 1 is reverts to the standard behaviour to make it an |
---|
10 | -long set by tzset(). Not really clean ... |
---|
11 | -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ |
---|
12 | - |
---|
13 | -#define __DARWIN_UNIX03 1 |
---|
14 | - |
---|
15 | #include <math.h> |
---|
16 | #include "pl-incl.h" |
---|
17 | #include "libtai/taia.h" |
---|
18 | @@ -41,8 +33,6 @@ |
---|
19 | #define daylight _daylight |
---|
20 | #else |
---|
21 | extern char *tzname[2]; |
---|
22 | -extern long timezone; |
---|
23 | -extern int daylight; |
---|
24 | #endif |
---|
25 | |
---|
26 | |
---|
27 | @@ -82,8 +72,24 @@ |
---|
28 | |
---|
29 | static int |
---|
30 | tz_offset() |
---|
31 | -{ do_tzset(); |
---|
32 | - return timezone; |
---|
33 | +{ time_t tloc; |
---|
34 | + struct tm result; |
---|
35 | + |
---|
36 | + tloc = time(NULL); |
---|
37 | + return localtime_r(&tloc, &result)->tm_gmtoff; |
---|
38 | +} |
---|
39 | + |
---|
40 | +/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
---|
41 | +tz_offset() returns the offset from UTC in seconds. |
---|
42 | +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ |
---|
43 | + |
---|
44 | +static int |
---|
45 | +tz_daylight() |
---|
46 | +{ time_t tloc; |
---|
47 | + struct tm result; |
---|
48 | + |
---|
49 | + tloc = time(NULL); |
---|
50 | + return localtime_r(&tloc, &result)->tm_isdst; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | @@ -312,7 +318,7 @@ |
---|
55 | ct.hour = tm.tm_hour; |
---|
56 | ct.minute = tm.tm_min; |
---|
57 | tzatom = tz_name_as_atom(tm.tm_isdst); |
---|
58 | - if ( daylight ) /* from tzset() */ |
---|
59 | + if ( tz_daylight() ) /* from tzset() */ |
---|
60 | { if ( tm.tm_isdst ) |
---|
61 | { utcoffset -= 3600; |
---|
62 | dstatom = ATOM_true; |
---|
63 | @@ -721,7 +727,7 @@ |
---|
64 | { localtime_r(&unixt, &tb.tm); |
---|
65 | tb.sec = (double)tb.tm.tm_sec + modf(tb.stamp, &ip); |
---|
66 | tb.utcoff = tz_offset(); |
---|
67 | - if ( daylight ) |
---|
68 | + if ( tz_daylight() ) |
---|
69 | { if ( tb.tm.tm_isdst ) |
---|
70 | { tb.utcoff -= 3600; |
---|
71 | tb.isdst = TRUE; |
---|