rom/exec/restoretaskstorage.c: Don't restore ETask data
[AROS.git] / compiler / clib / gettimeofday.c
blobe70a1deabd620d4fd8bfa53a6a0297270c64ea00
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Query the current time and/or timezone.
6 */
8 #include "__arosc_privdata.h"
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/timer.h>
13 #include <proto/locale.h>
14 #include <exec/types.h>
15 #include <devices/timer.h>
16 #include <aros/symbolsets.h>
17 #include <aros/debug.h>
19 #include <time.h>
21 /*****************************************************************************
23 NAME */
24 #include <sys/time.h>
25 #include <unistd.h>
27 int gettimeofday (
29 /* SYNOPSIS */
30 struct timeval * tv,
31 struct timezone * tz)
33 /* FUNCTION
34 Return the current time and/or timezone.
36 INPUTS
37 tv - If this pointer is non-NULL, the current time will be
38 stored here. The structure looks like this:
40 struct timeval
42 long tv_sec; // seconds
43 long tv_usec; // microseconds
46 tz - If this pointer is non-NULL, the current timezone will be
47 stored here. The structure looks like this:
49 struct timezone
51 int tz_minuteswest; // minutes west of Greenwich
52 int tz_dsttime; // type of dst correction
55 With daylight savings times defined as follows :
57 DST_NONE // not on dst
58 DST_USA // USA style dst
59 DST_AUST // Australian style dst
60 DST_WET // Western European dst
61 DST_MET // Middle European dst
62 DST_EET // Eastern European dst
63 DST_CAN // Canada
64 DST_GB // Great Britain and Eire
65 DST_RUM // Rumania
66 DST_TUR // Turkey
67 DST_AUSTALT // Australian style with shift in 1986
69 And the following macros are defined to operate on this :
71 timerisset(tv) - TRUE if tv contains a time
73 timercmp(tv1, tv2, cmp) - Return the result of the
74 comparison "tv1 cmp tv2"
76 timerclear(tv) - Clear the timeval struct
78 RESULT
79 The number of seconds.
81 NOTES
82 This function must not be used in a shared library or
83 in a threaded application.
85 EXAMPLE
86 struct timeval tv;
88 // Get the current time and print it
89 gettimeofday (&tv, NULL);
91 printf ("Seconds = %ld, uSec = %ld\n", tv->tv_sec, tv->tv_usec);
93 BUGS
95 SEE ALSO
96 ctime(), asctime(), localtime(), time()
98 INTERNALS
100 ******************************************************************************/
102 struct aroscbase *aroscbase = __GM_GetBase();
104 if (tv)
106 GetSysTime(tv);
108 /* Adjust with the current timezone, stored in minutes west of GMT */
109 tv->tv_sec += (2922 * 1440 + aroscbase->acb_gmtoffset) * 60;
112 if (tz)
114 tz->tz_minuteswest = aroscbase->acb_gmtoffset;
115 /* FIXME: set tz->tz_dsttime */
116 tz->tz_dsttime = DST_NONE;
119 return 0;
120 } /* gettimeofday */
123 struct Device *TimerBase;
125 static int __init_timerbase(struct aroscbase *aroscbase)
127 aroscbase->acb_timeport.mp_Node.ln_Type = NT_MSGPORT;
128 aroscbase->acb_timeport.mp_Node.ln_Pri = 0;
129 aroscbase->acb_timeport.mp_Node.ln_Name = NULL;
130 aroscbase->acb_timeport.mp_Flags = PA_IGNORE;
131 aroscbase->acb_timeport.mp_SigTask = FindTask(NULL);
132 aroscbase->acb_timeport.mp_SigBit = 0;
133 NEWLIST(&aroscbase->acb_timeport.mp_MsgList);
135 aroscbase->acb_timereq.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
136 aroscbase->acb_timereq.tr_node.io_Message.mn_Node.ln_Pri = 0;
137 aroscbase->acb_timereq.tr_node.io_Message.mn_Node.ln_Name = NULL;
138 aroscbase->acb_timereq.tr_node.io_Message.mn_ReplyPort = &aroscbase->acb_timeport;
139 aroscbase->acb_timereq.tr_node.io_Message.mn_Length = sizeof (aroscbase->acb_timereq);
141 struct Locale *locale = OpenLocale(NULL);
142 if (locale)
144 aroscbase->acb_gmtoffset = locale->loc_GMTOffset;
145 CloseLocale(locale);
147 else
148 aroscbase->acb_gmtoffset = 0;
152 OpenDevice
154 "timer.device",
155 UNIT_VBLANK,
156 (struct IORequest *)&aroscbase->acb_timereq,
163 TimerBase = (struct Device *)aroscbase->acb_timereq.tr_node.io_Device;
164 return 1;
166 else
168 return 0;
173 static void __exit_timerbase(struct aroscbase *aroscbase)
175 if (TimerBase != NULL)
176 CloseDevice((struct IORequest *)&aroscbase->acb_timereq);
179 ADD2OPENLIB(__init_timerbase, 0);
180 ADD2CLOSELIB(__exit_timerbase, 0);