x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / time.c
blobbd6f40f7ca5f7f9777cdf4a857b96e338cf96df8
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Return the current time in seconds.
6 */
8 #include <proto/exec.h>
9 #include <proto/timer.h>
11 #include <errno.h>
13 #include "__stdc_intbase.h"
15 #define DEBUG 0
16 #include <aros/debug.h>
18 static int __init_timerbase(struct StdCIntBase *StdCBase);
19 struct Device *TimerBase = NULL;
21 /*****************************************************************************
23 NAME */
24 #include <time.h>
26 time_t time (
28 /* SYNOPSIS */
29 time_t * tloc)
31 /* FUNCTION
32 time() returns the time since 00:00:00 GMT, January 1, 1970,
33 measured in seconds.
35 INPUTS
36 tloc - If this pointer is non-NULL, then the time is written into
37 this variable as well.
39 RESULT
40 The number of seconds.
42 NOTES
43 This function must not be used in a shared library or
44 in a threaded application.
46 EXAMPLE
47 time_t tt1, tt2;
49 // tt1 and tt2 are the same
50 tt1 = time (&tt2);
52 // This is valid, too
53 tt1 = time (NULL);
55 BUGS
57 SEE ALSO
58 ctime(), asctime(), localtime()
60 INTERNALS
62 ******************************************************************************/
64 struct timeval tv;
66 /* We get TimerBase here and not during LIBINIT because timer.device is not available
67 when stdc.library is initialized.
69 if (TimerBase == NULL)
70 __init_timerbase((struct StdCIntBase *)__aros_getbase_StdCBase());
71 if (TimerBase == NULL)
73 errno = EACCES;
74 return (time_t)-1;
77 GetSysTime(&tv);
78 tv.tv_sec += 2922 * 1440 * 60;
80 tv.tv_sec += __stdc_gmtoffset() * 60;
82 if (tloc)
83 *tloc = tv.tv_sec;
84 return tv.tv_sec;
85 } /* time */
88 static int __init_timerbase(struct StdCIntBase *StdCBase)
90 D(bug("__init_timerbase\n"));
92 StdCBase->timeport.mp_Node.ln_Type = NT_MSGPORT;
93 StdCBase->timeport.mp_Node.ln_Pri = 0;
94 StdCBase->timeport.mp_Node.ln_Name = NULL;
95 StdCBase->timeport.mp_Flags = PA_IGNORE;
96 StdCBase->timeport.mp_SigTask = FindTask(NULL);
97 StdCBase->timeport.mp_SigBit = 0;
98 NEWLIST(&StdCBase->timeport.mp_MsgList);
100 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
101 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Pri = 0;
102 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Name = NULL;
103 StdCBase->timereq.tr_node.io_Message.mn_ReplyPort = &StdCBase->timeport;
104 StdCBase->timereq.tr_node.io_Message.mn_Length = sizeof (StdCBase->timereq);
106 if (OpenDevice(
107 "timer.device", UNIT_VBLANK,
108 (struct IORequest *)&StdCBase->timereq, 0
109 ) == 0
112 TimerBase = (struct Device *)StdCBase->timereq.tr_node.io_Device;
113 D(bug("__init_timerbase TimerBase=%x\n", TimerBase));
114 return 1;
116 else
118 D(bug("__init_timerbase OpenDevice failed\n"));
119 return 0;
124 static void __exit_timerbase(struct StdCIntBase *StdCBase)
126 D(bug("__exit_timerbase\n"));
128 if (TimerBase != NULL)
130 CloseDevice((struct IORequest *)&StdCBase->timereq);
131 TimerBase = NULL;
135 ADD2EXPUNGELIB(__exit_timerbase, 0);