]> www.ginac.de Git - cln.git/blob - src/timing/cl_t_current.cc
Rework of autoconfiscation infrastructure
[cln.git] / src / timing / cl_t_current.cc
1 // cl_current_time().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/timing.h"
8
9
10 // Implementation.
11
12 #include "cl_t_config.h"
13
14
15 #if defined(HAVE_GETTIMEOFDAY)
16   #include <sys/time.h>
17   #ifdef GETTIMEOFDAY_DOTS
18     extern "C" int gettimeofday (struct timeval * tp, ...);
19   #else
20     extern "C" int gettimeofday (struct timeval * tp, GETTIMEOFDAY_TZP_T tzp);
21   #endif
22 #else
23   #include <time.h>
24 #endif
25 #ifdef HAVE_PERROR_DECL
26   #include <errno.h>
27   #include <stdio.h>
28 #else
29   extern "C" int perror (const char *);
30 #endif
31
32 namespace cln {
33
34 const cl_timespec cl_current_time ()
35 {
36 #if defined(HAVE_GETTIMEOFDAY)
37         var struct timeval tv;
38         if (gettimeofday(&tv,NULL) != 0) {
39                 perror("gettimeofday");
40                 tv.tv_sec = 0; tv.tv_usec = 0;
41         }
42         return cl_timespec(tv.tv_sec,
43                            tv.tv_usec * (1000000000/1000000)
44                           );
45 #else
46         return cl_timespec(time(NULL),0);
47 #endif
48 }
49
50 }  // namespace cln