e9b4bdaf38a628ad3867904f1a3b281759c88371
[ghc-hetmet.git] / ghc / lib / std / cbits / timezone.h
1 #ifndef TIMEZONE_H
2 #define TIMEZONE_H
3
4 #define _OSF_SOURCE
5
6 #if linux_TARGET_OS
7 /* Sigh, RedHat 5 has the TM_ZONE stuff, but only when _BSD_SOURCE is
8  * on.  The configure script erroneously says we've got TM_ZONE, so
9  * make sure we use the TZNAME stuff instead.
10  *
11  * Aside: tzname is POSIX, whereas tm_zone is BSD.  We should be using
12  *  tzname by preference, but the GNU configure stuff gives us HAVE_TM_ZONE
13  *  in preference to HAVE_TZNAME.  More sighs.
14  */
15 # undef  HAVE_TM_ZONE
16 # define HAVE_TZNAME  1
17 #endif
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #if HAVE_TM_ZONE
31 #define ZONE(x)          (((struct tm *)x)->tm_zone)
32 #define SETZONE(x,z)     (((struct tm *)x)->tm_zone = z)
33 #define GMTOFF(x)        (((struct tm *)x)->tm_gmtoff)
34 #else /* ! HAVE_TM_ZONE */
35 # if HAVE_TZNAME || cygwin32_TARGET_OS
36 #if cygwin32_TARGET_OS
37 extern char *tzname;
38 #else
39 extern char *tzname[2];
40 #endif
41 #  define ZONE(x)        (((struct tm *)x)->tm_isdst ? tzname[1] : tzname[0])
42 #  define SETZONE(x,z)
43 # else /* ! HAVE_TZNAME */
44 /* We're in trouble. If you should end up here, please report this as a bug. */
45 #  error Dont know how to get at timezone name on your OS.
46 # endif /* ! HAVE_TZNAME */
47 /* Get the offset in secs from UTC, if (struct tm) doesn't supply it. */
48
49 extern TYPE_TIMEZONE timezone;
50
51 # if HAVE_ALTZONE
52 extern time_t altzone;
53 #  define GMTOFF(x)      (((struct tm *)x)->tm_isdst ? altzone : timezone)
54 # else /* ! HAVE_ALTZONE */
55 /* Assume that DST offset is 1 hour ... */
56 #  define GMTOFF(x) (((struct tm *)x)->tm_isdst ? (timezone - 3600) : timezone)
57 # endif /* ! HAVE_ALTZONE */
58 #endif  /* ! HAVE_TM_ZONE */
59
60 #endif /* TIMEZONE_H */