git.fiddlerwoaroof.com
Browse code

adds source code complexity

Greg Wiley authored on 28/03/2017 18:20:35
Showing 1 changed files
... ...
@@ -1,16 +1,33 @@
1 1
 #include <stdio.h>
2 2
 #include <sys/time.h>
3
+#include "config.h"
3 4
 
4
-int main(int argc, char* argv[])
5
+#ifdef HAVE_SYS_TIME_H
6
+    #include <sys/time.h>
7
+#else
8
+    #include <time.h>
9
+#endif
10
+
11
+double get_sec_since_epoch()
5 12
 {
6 13
     double sec;
7
-    struct timeval tv;
8 14
 
9
-    gettimeofday(&tv, NULL);
10
-    sec = tv.tv_sec;
11
-    sec += tv.tv_usec / 1000000.0;
15
+    #ifdef HAVE_GETTIMEOFDAY
16
+        struct timeval tv;
12 17
 
13
-    printf("%f\n", sec);
18
+        gettimeofday(&tv, NULL);
19
+        sec = tv.tv_sec;
20
+        sec += tv.tv_usec / 1000000.0;
21
+    #else
22
+        sec = time(NULL);
23
+    #endif
24
+
25
+    return sec;
26
+}
27
+
28
+int main(int argc, char* argv[])
29
+{
30
+    printf("%f\n", get_sec_since_epoch());
14 31
 
15 32
     return 0;
16 33
 }