]> pd.if.org Git - pdclib/blob - platform/example/functions/time/time.c
POSIX interfacing time retrieval
[pdclib] / platform / example / functions / time / time.c
1 /* time( time_t * )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <time.h>
8
9 #ifndef REGTEST
10
11 #include <sys/time.h>
12
13 /* See comments in time.h on the semantics of time_t. */
14
15 time_t time( time_t * timer )
16 {
17     struct timeval tv;
18     if ( gettimeofday( &tv, NULL ) == 0 )
19     {
20         if ( timer != NULL )
21         {
22             *timer = tv.tv_sec;
23         }
24         return tv.tv_sec;
25     }
26     return -1;
27 }
28
29 #endif
30
31 #ifdef TEST
32
33 #include "_PDCLIB_test.h"
34
35 int main( void )
36 {
37     TESTCASE( NO_TESTDRIVER );
38     return TEST_RESULTS;
39 }
40
41 #endif