]> pd.if.org Git - pdclib/blob - platform/example/functions/time/timespec_get.c
POSIX interfacing time retrieval
[pdclib] / platform / example / functions / time / timespec_get.c
1 /* timespec_get( struct timespec *, int )
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 int timespec_get( struct timespec * ts, int base )
14 {
15     if ( base == TIME_UTC )
16     {
17         /* We can make do with a really thin wrapper here. */
18         struct timeval tv;
19         if ( gettimeofday( &tv, NULL ) == 0 )
20         {
21             ts->tv_sec = tv.tv_sec;
22             ts->tv_nsec = tv.tv_usec * 1000;
23             return base;
24         }
25     }
26     /* Not supporting any other time base than TIME_UTC for now. */
27     return 0;
28 }
29
30 #endif
31
32 #ifdef TEST
33
34 #include "_PDCLIB_test.h"
35
36 int main( void )
37 {
38     TESTCASE( NO_TESTDRIVER );
39     return TEST_RESULTS;
40 }
41
42 #endif