2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Query the current time and/or timezone.
8 #include <proto/exec.h>
10 #include <proto/timer.h>
11 #include <proto/locale.h>
12 #include <exec/types.h>
13 #include <devices/timer.h>
14 #include <aros/symbolsets.h>
15 #include <aros/debug.h>
20 struct Device
*TimerBase
;
21 static void __init_timerbase(void);
23 /*****************************************************************************
35 Return the current time and/or timezone.
38 tv - If this pointer is non-NULL, the current time will be
39 stored here. The structure looks like this:
43 long tv_sec; // seconds
44 long tv_usec; // microseconds
47 tz - If this pointer is non-NULL, the current timezone will be
48 stored here. The structure looks like this:
52 int tz_minuteswest; // minutes west of Greenwich
53 int tz_dsttime; // type of dst correction
56 With daylight savings times defined as follows :
58 DST_NONE // not on dst
59 DST_USA // USA style dst
60 DST_AUST // Australian style dst
61 DST_WET // Western European dst
62 DST_MET // Middle European dst
63 DST_EET // Eastern European dst
65 DST_GB // Great Britain and Eire
68 DST_AUSTALT // Australian style with shift in 1986
70 And the following macros are defined to operate on this :
72 timerisset(tv) - TRUE if tv contains a time
74 timercmp(tv1, tv2, cmp) - Return the result of the
75 comparison "tv1 cmp tv2"
77 timerclear(tv) - Clear the timeval struct
80 The number of seconds.
83 This function must not be used in a shared library or
84 in a threaded application.
89 // Get the current time and print it
90 gettimeofday (&tv, NULL);
92 printf ("Seconds = %ld, uSec = %ld\n", tv->tv_sec, tv->tv_usec);
97 stdc.library/ctime(), stdc.library/asctime(), stdc.library/localtime(),
102 ******************************************************************************/
113 /* Adjust with the current timezone, stored in minutes west of GMT */
114 tv
->tv_sec
+= (2922 * 1440 + __stdc_gmtoffset()) * 60;
125 tz
->tz_minuteswest
= __stdc_gmtoffset();
126 /* FIXME: set tz->tz_dsttime */
127 tz
->tz_dsttime
= DST_NONE
;
134 static struct timerequest __timereq
;
135 static struct MsgPort __timeport
;
137 static void __init_timerbase(void)
139 __timeport
.mp_Node
.ln_Type
= NT_MSGPORT
;
140 __timeport
.mp_Node
.ln_Pri
= 0;
141 __timeport
.mp_Node
.ln_Name
= NULL
;
142 __timeport
.mp_Flags
= PA_IGNORE
;
143 __timeport
.mp_SigTask
= FindTask(NULL
);
144 __timeport
.mp_SigBit
= 0;
145 NEWLIST(&__timeport
.mp_MsgList
);
147 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
148 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Pri
= 0;
149 __timereq
.tr_node
.io_Message
.mn_Node
.ln_Name
= NULL
;
150 __timereq
.tr_node
.io_Message
.mn_ReplyPort
= &__timeport
;
151 __timereq
.tr_node
.io_Message
.mn_Length
= sizeof (__timereq
);
159 (struct IORequest
*)&__timereq
,
166 TimerBase
= (struct Device
*)__timereq
.tr_node
.io_Device
;
171 static void __exit_timerbase(APTR dummy
)
173 if (TimerBase
!= NULL
)
175 CloseDevice((struct IORequest
*)&__timereq
);
180 ADD2EXIT(__exit_timerbase
, 0);