]> www.ginac.de Git - cln.git/blob - src/timing/cl_t_current.cc
93b40d23eb48ab998e42f46929693d757e70715c
[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 "cl_timing.h"
8
9
10 // Implementation.
11
12 #include "cl_t_config.h"
13
14 #if defined(HAVE_GETTIMEOFDAY)
15   #include <sys/time.h>
16   #ifdef GETTIMEOFDAY_DOTS
17     extern "C" int gettimeofday (struct timeval * tp, ...);
18   #else
19     extern "C" int gettimeofday (struct timeval * tp, GETTIMEOFDAY_TZP_T tzp);
20   #endif
21 #elif defined(HAVE_FTIME)
22   #include <sys/timeb.h>
23   #ifdef _WIN32
24     extern "C" void ftime (struct timeb * tp);
25   #else
26     extern "C" int ftime (struct timeb * tp);
27   #endif
28 #else
29   #include <time.h>
30 #endif
31 #ifdef HAVE_PERROR_DECL
32   #include <errno.h>
33   #include <stdio.h>
34 #else
35   extern "C" int perror (const char *);
36 #endif
37
38 const cl_timespec cl_current_time ()
39 {
40 #if defined(HAVE_GETTIMEOFDAY)
41         var struct timeval tv;
42         if (gettimeofday(&tv,NULL) != 0) {
43                 perror("gettimeofday");
44                 tv.tv_sec = 0; tv.tv_usec = 0;
45         }
46         return cl_timespec(tv.tv_sec,
47                            tv.tv_usec * (1000000000/1000000)
48                           );
49 #elif defined(HAVE_FTIME)
50         var struct timeb timebuf;
51         ftime(&timebuf);
52         return cl_timespec(timebuf.time,
53                            (uintL)timebuf.millitm * (1000000000/1000)
54                           );
55 #else
56         return cl_timespec(time(NULL),0);
57 #endif
58 }