aa28ea69d132ee3796f828f464ecd55ad890d8c5
[ghc-hetmet.git] / ghc / lib / std / cbits / timezone.h
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
3  *
4  * $Id: timezone.h,v 1.9 1999/05/05 10:33:17 sof Exp $
5  *
6  * Time-zone support header
7  */
8
9 #ifndef TIMEZONE_H
10 #define TIMEZONE_H
11
12 #define _OSF_SOURCE
13
14 #if HAVE_SYS_TYPES_H
15 # include <sys/types.h>
16 #endif
17
18 #if linux_TARGET_OS
19 /* Sigh, RedHat 5 has the TM_ZONE stuff, but only when _BSD_SOURCE is
20  * on.  The configure script erroneously says we've got TM_ZONE, so
21  * make sure we use the TZNAME stuff instead.
22  *
23  * Aside: tzname is POSIX, whereas tm_zone is BSD.  We should be using
24  *  tzname by preference, but the GNU configure stuff gives us HAVE_TM_ZONE
25  *  in preference to HAVE_TZNAME.  More sighs.
26  */
27 # undef  HAVE_TM_ZONE
28 # define HAVE_TZNAME  1
29
30 /* Double sigh.  The timezone variable is only available under Linux
31  * when we're compiling NON_POSIX_SOURCE (or _GNU_SOURCE or whatever),
32  * but to make that work we have to make sure NON_POSIX_SOURCE is
33  * defined before anything from /usr/include is included.  To avoid
34  * infecting too much source with NON_POSIX_SOURCE, we frob it
35  * below...
36  */
37 #undef HAVE_TIMEZONE
38
39 /* The correct solution to this problem would appear to be to ditch
40  * the standard GNU configure tests for the time stuff, and hack up
41  * our own that test for POSIX-compliant time support first, then
42  * BSD-style time stuff.
43  */
44 #endif
45
46 #ifdef solaris2_TARGET_OS
47 #undef HAVE_TIMEZONE
48 #endif
49
50 #if TIME_WITH_SYS_TIME
51 # include <sys/time.h>
52 # include <time.h>
53 #else
54 # if HAVE_SYS_TIME_H
55 #  include <sys/time.h>
56 # else
57 #  include <time.h>
58 # endif
59 #endif
60
61 #if HAVE_TM_ZONE
62 #define ZONE(x)          (((struct tm *)x)->tm_zone)
63 #define SETZONE(x,z)     (((struct tm *)x)->tm_zone = z)
64 #define GMTOFF(x)        (((struct tm *)x)->tm_gmtoff)
65 #else /* ! HAVE_TM_ZONE */
66 # if HAVE_TZNAME || _WIN32
67 #  if cygwin32_TARGET_OS
68 #   define tzname _tzname
69 #  endif
70 #  ifndef mingw32_TARGET_OS
71 extern char *tzname[2];
72 #  endif
73
74 #  define ZONE(x)        (((struct tm *)x)->tm_isdst ? tzname[1] : tzname[0])
75 #  define SETZONE(x,z)
76 # else /* ! HAVE_TZNAME */
77 /* We're in trouble. If you should end up here, please report this as a bug. */
78 #  error Dont know how to get at timezone name on your OS.
79 # endif /* ! HAVE_TZNAME */
80 /* Get the offset in secs from UTC, if (struct tm) doesn't supply it. */
81
82 #ifdef mingw32_TARGET_OS
83 #define timezone _timezone
84 #else
85 # ifdef cygwin32_TARGET_OS
86 #  define timezone _timezone
87 # endif
88 #endif
89
90 #ifndef HAVE_TIMEZONE
91 extern TYPE_TIMEZONE timezone;
92 #endif
93
94 # if HAVE_ALTZONE
95 extern time_t altzone;
96 #  define GMTOFF(x)      (((struct tm *)x)->tm_isdst ? altzone : timezone )
97 # else /* ! HAVE_ALTZONE */
98 /* Assume that DST offset is 1 hour ... */
99 #  define GMTOFF(x) (((struct tm *)x)->tm_isdst ? (timezone - 3600) : timezone )
100 # endif /* ! HAVE_ALTZONE */
101 #endif  /* ! HAVE_TM_ZONE */
102
103 #endif /* TIMEZONE_H */