]> www.ginac.de Git - cln.git/blob - src/timing/cl_t_current.cc
* All Files have been modified for inclusion of namespace cln;
[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 #elif defined(HAVE_FTIME)
23   #include <sys/timeb.h>
24   #ifdef _WIN32
25     extern "C" void ftime (struct timeb * tp);
26   #else
27     extern "C" int ftime (struct timeb * tp);
28   #endif
29 #else
30   #include <time.h>
31 #endif
32 #ifdef HAVE_PERROR_DECL
33   #include <errno.h>
34   #include <stdio.h>
35 #else
36   extern "C" int perror (const char *);
37 #endif
38
39 namespace cln {
40
41 const cl_timespec cl_current_time ()
42 {
43 #if defined(HAVE_GETTIMEOFDAY)
44         var struct timeval tv;
45         if (gettimeofday(&tv,NULL) != 0) {
46                 perror("gettimeofday");
47                 tv.tv_sec = 0; tv.tv_usec = 0;
48         }
49         return cl_timespec(tv.tv_sec,
50                            tv.tv_usec * (1000000000/1000000)
51                           );
52 #elif defined(HAVE_FTIME)
53         var struct timeb timebuf;
54         ftime(&timebuf);
55         return cl_timespec(timebuf.time,
56                            (uintL)timebuf.millitm * (1000000000/1000)
57                           );
58 #else
59         return cl_timespec(time(NULL),0);
60 #endif
61 }
62
63 }  // namespace cln