arch/m68k-amiga: Define the gcc symbol 'start' instead of using .bss
[AROS.git] / compiler / clib / gettimeofday.c
blob2671fe822a1a3480c5870c228066e0f649badd28
1 /*
2 Copyright © 1995-2011, 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>
18 #include <libraries/locale.h>
21 #include "__time.h"
23 /*****************************************************************************
25 NAME */
26 #include <sys/time.h>
27 #include <unistd.h>
29 int gettimeofday (
31 /* SYNOPSIS */
32 struct timeval * tv,
33 struct timezone * tz)
35 /* FUNCTION
36 Return the current time and/or timezone.
38 INPUTS
39 tv - If this pointer is non-NULL, the current time will be
40 stored here. The structure looks like this:
42 struct timeval
44 long tv_sec; // seconds
45 long tv_usec; // microseconds
48 tz - If this pointer is non-NULL, the current timezone will be
49 stored here. The structure looks like this:
51 struct timezone
53 int tz_minuteswest; // minutes west of Greenwich
54 int tz_dsttime; // type of dst correction
57 With daylight savings times defined as follows :
59 DST_NONE // not on dst
60 DST_USA // USA style dst
61 DST_AUST // Australian style dst
62 DST_WET // Western European dst
63 DST_MET // Middle European dst
64 DST_EET // Eastern European dst
65 DST_CAN // Canada
66 DST_GB // Great Britain and Eire
67 DST_RUM // Rumania
68 DST_TUR // Turkey
69 DST_AUSTALT // Australian style with shift in 1986
71 And the following macros are defined to operate on this :
73 timerisset(tv) - TRUE if tv contains a time
75 timercmp(tv1, tv2, cmp) - Return the result of the
76 comparison "tv1 cmp tv2"
78 timerclear(tv) - Clear the timeval struct
80 RESULT
81 The number of seconds.
83 NOTES
84 This function must not be used in a shared library or
85 in a threaded application.
87 EXAMPLE
88 struct timeval tv;
90 // Get the current time and print it
91 gettimeofday (&tv, NULL);
93 printf ("Seconds = %ld, uSec = %ld\n", tv->tv_sec, tv->tv_usec);
95 BUGS
97 SEE ALSO
98 ctime(), asctime(), localtime(), time()
100 INTERNALS
102 ******************************************************************************/
104 if (tv)
106 GetSysTime(tv);
108 /* Adjust with the current timezone, stored in minutes west of GMT */
109 tv->tv_sec += (2922 * 1440 + __gmtoffset) * 60;
112 if (tz)
114 tz->tz_minuteswest = __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(void)
127 __timeport.mp_Node.ln_Type = NT_MSGPORT;
128 __timeport.mp_Node.ln_Pri = 0;
129 __timeport.mp_Node.ln_Name = NULL;
130 __timeport.mp_Flags = PA_IGNORE;
131 __timeport.mp_SigTask = FindTask(NULL);
132 __timeport.mp_SigBit = 0;
133 NEWLIST(&__timeport.mp_MsgList);
135 __timereq.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
136 __timereq.tr_node.io_Message.mn_Node.ln_Pri = 0;
137 __timereq.tr_node.io_Message.mn_Node.ln_Name = NULL;
138 __timereq.tr_node.io_Message.mn_ReplyPort = &__timeport;
139 __timereq.tr_node.io_Message.mn_Length = sizeof (__timereq);
141 struct Locale *locale = OpenLocale(NULL);
142 if (locale)
144 __gmtoffset = locale->loc_GMTOffset;
145 CloseLocale(locale);
147 else
148 __gmtoffset = 0;
152 OpenDevice
154 "timer.device",
155 UNIT_VBLANK,
156 (struct IORequest *)&__timereq,
163 TimerBase = (struct Device *)__timereq.tr_node.io_Device;
164 return 1;
166 else
168 return 0;
173 static void __exit_timerbase(void)
175 if (TimerBase != NULL)
176 CloseDevice((struct IORequest *)&__timereq);
179 ADD2OPENLIB(__init_timerbase, 0);
180 ADD2CLOSELIB(__exit_timerbase, 0);