revert between 56095 -> 55830 in arch
[AROS.git] / compiler / stdc / time.c
blob2e393e4a0fd5cfd7b236d6eb536c9565c45257e7
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>
10 #define __NOBLIBBASE__
12 #include <proto/timer.h>
14 #include <errno.h>
16 #include "__stdc_intbase.h"
18 #define DEBUG 0
19 #include <aros/debug.h>
21 static int __init_timerbase(struct StdCIntBase *StdCBase);
22 #define TimerBase StdCBase->StdCTimerBase
24 /*****************************************************************************
26 NAME */
27 #include <time.h>
29 time_t time (
31 /* SYNOPSIS */
32 time_t * tloc)
34 /* FUNCTION
35 time() returns the time since 00:00:00 GMT, January 1, 1970,
36 measured in seconds.
38 INPUTS
39 tloc - If this pointer is non-NULL, then the time is written into
40 this variable as well.
42 RESULT
43 The number of seconds.
45 NOTES
46 This function must not be used in a shared library or
47 in a threaded application.
49 EXAMPLE
50 time_t tt1, tt2;
52 // tt1 and tt2 are the same
53 tt1 = time (&tt2);
55 // This is valid, too
56 tt1 = time (NULL);
58 BUGS
60 SEE ALSO
61 ctime(), asctime(), localtime()
63 INTERNALS
65 ******************************************************************************/
67 struct StdCIntBase *StdCBase = (struct StdCIntBase *)__aros_getbase_StdCBase();
68 struct timeval tv;
70 /* We get TimerBase here and not during LIBINIT because timer.device is not available
71 when stdc.library is initialized.
73 if (TimerBase == NULL)
74 __init_timerbase(StdCBase);
75 if (TimerBase == NULL)
77 errno = EACCES;
78 return (time_t)-1;
81 GetSysTime(&tv);
82 tv.tv_sec += 2922 * 1440 * 60;
84 tv.tv_sec += __stdc_gmtoffset() * 60;
86 if (tloc)
87 *tloc = tv.tv_sec;
88 return tv.tv_sec;
89 } /* time */
92 static int __init_timerbase(struct StdCIntBase *StdCBase)
94 D(bug("__init_timerbase\n"));
96 memset( &StdCBase->timeport, 0, sizeof( StdCBase->timeport ) );
97 StdCBase->timeport.mp_Node.ln_Type = NT_MSGPORT;
98 StdCBase->timeport.mp_Flags = PA_IGNORE;
99 StdCBase->timeport.mp_SigTask = FindTask(NULL);
100 NEWLIST(&StdCBase->timeport.mp_MsgList);
102 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
103 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Pri = 0;
104 StdCBase->timereq.tr_node.io_Message.mn_Node.ln_Name = NULL;
105 StdCBase->timereq.tr_node.io_Message.mn_ReplyPort = &StdCBase->timeport;
106 StdCBase->timereq.tr_node.io_Message.mn_Length = sizeof (StdCBase->timereq);
108 if (OpenDevice(
109 "timer.device", UNIT_VBLANK,
110 (struct IORequest *)&StdCBase->timereq, 0
111 ) == 0
114 TimerBase = (struct Device *)StdCBase->timereq.tr_node.io_Device;
115 D(bug("__init_timerbase TimerBase=%x\n", TimerBase));
116 return 1;
118 else
120 D(bug("__init_timerbase OpenDevice failed\n"));
121 return 0;
126 static void __exit_timerbase(struct StdCIntBase *StdCBase)
128 D(bug("__exit_timerbase\n"));
130 if (TimerBase != NULL)
132 CloseDevice((struct IORequest *)&StdCBase->timereq);
133 TimerBase = NULL;
137 ADD2EXPUNGELIB(__exit_timerbase, 0);