forwarding a patch that uses the fetch macros to pull in acpica and build it (NicJA).
[AROS.git] / compiler / posixc / gettimeofday.c
blobb3108a01b296cce58cf08062897f03308860a634
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 $Id$
5 Query the current time and/or timezone.
6 */
8 #include <proto/exec.h>
9 #include <proto/timer.h>
10 #include <exec/types.h>
11 #include <aros/symbolsets.h>
12 #include <aros/debug.h>
14 #include <time.h>
15 #include <errno.h>
17 #include "__posixc_time.h"
19 /*****************************************************************************
21 NAME */
22 #include <sys/time.h>
24 int gettimeofday (
26 /* SYNOPSIS */
27 struct timeval * tv,
28 struct timezone * tz)
30 /* FUNCTION
31 Return the current time and/or timezone.
33 INPUTS
34 tv - If this pointer is non-NULL, the current time will be
35 stored here. The structure looks like this:
37 struct timeval
39 long tv_sec; // seconds
40 long tv_usec; // microseconds
43 tz - If this pointer is non-NULL, the current timezone will be
44 stored here. The structure looks like this:
46 struct timezone
48 int tz_minuteswest; // minutes west of Greenwich
49 int tz_dsttime; // type of dst correction
52 With daylight savings times defined as follows :
54 DST_NONE // not on dst
55 DST_USA // USA style dst
56 DST_AUST // Australian style dst
57 DST_WET // Western European dst
58 DST_MET // Middle European dst
59 DST_EET // Eastern European dst
60 DST_CAN // Canada
61 DST_GB // Great Britain and Eire
62 DST_RUM // Rumania
63 DST_TUR // Turkey
64 DST_AUSTALT // Australian style with shift in 1986
66 And the following macros are defined to operate on this :
68 timerisset(tv) - TRUE if tv contains a time
70 timercmp(tv1, tv2, cmp) - Return the result of the
71 comparison "tv1 cmp tv2"
73 timerclear(tv) - Clear the timeval struct
75 RESULT
76 The number of seconds.
78 NOTES
79 This function must not be used in a shared library or
80 in a threaded application.
82 EXAMPLE
83 struct timeval tv;
85 // Get the current time and print it
86 gettimeofday (&tv, NULL);
88 printf ("Seconds = %ld, uSec = %ld\n", tv->tv_sec, tv->tv_usec);
90 BUGS
92 SEE ALSO
93 stdc.library/ctime(), stdc.library/asctime(), stdc.library/localtime(),
94 stdc.library/time()
96 INTERNALS
98 ******************************************************************************/
100 struct PosixCIntBase *PosixCBase = (struct PosixCIntBase *)__aros_getbase_PosixCBase();
102 if (!TimerBase)
103 __init_timerbase(PosixCBase);
105 if (tv)
107 if (TimerBase)
109 GetSysTime(tv);
111 /* Adjust with the current timezone, stored in minutes west of GMT */
112 tv->tv_sec += (2922 * 1440 + __stdc_gmtoffset()) * 60;
114 else
116 errno = EACCES;
117 return -1;
121 if (tz)
123 tz->tz_minuteswest = __stdc_gmtoffset();
124 /* FIXME: set tz->tz_dsttime */
125 tz->tz_dsttime = DST_NONE;
128 return 0;
129 } /* gettimeofday */