[project @ 1998-12-02 13:17:09 by simonm]
[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.3 1998/12/02 13:28:01 simonm 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 #endif
30
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
33 # include <time.h>
34 #else
35 # if HAVE_SYS_TIME_H
36 #  include <sys/time.h>
37 # else
38 #  include <time.h>
39 # endif
40 #endif
41
42 #if HAVE_TM_ZONE
43 #define ZONE(x)          (((struct tm *)x)->tm_zone)
44 #define SETZONE(x,z)     (((struct tm *)x)->tm_zone = z)
45 #define GMTOFF(x)        (((struct tm *)x)->tm_gmtoff)
46 #else /* ! HAVE_TM_ZONE */
47 # if HAVE_TZNAME || cygwin32_TARGET_OS
48 #if cygwin32_TARGET_OS
49 #define tzname _tzname
50 #endif
51 extern char *tzname[2];
52 #  define ZONE(x)        (((struct tm *)x)->tm_isdst ? tzname[1] : tzname[0])
53 #  define SETZONE(x,z)
54 # else /* ! HAVE_TZNAME */
55 /* We're in trouble. If you should end up here, please report this as a bug. */
56 #  error Dont know how to get at timezone name on your OS.
57 # endif /* ! HAVE_TZNAME */
58 /* Get the offset in secs from UTC, if (struct tm) doesn't supply it. */
59
60 extern TYPE_TIMEZONE timezone;
61
62 # if HAVE_ALTZONE
63 extern time_t altzone;
64 #  define GMTOFF(x)      (((struct tm *)x)->tm_isdst ? altzone : timezone)
65 # else /* ! HAVE_ALTZONE */
66 /* Assume that DST offset is 1 hour ... */
67 #  define GMTOFF(x) (((struct tm *)x)->tm_isdst ? (timezone - 3600) : timezone)
68 # endif /* ! HAVE_ALTZONE */
69 #endif  /* ! HAVE_TM_ZONE */
70
71 #endif /* TIMEZONE_H */