cmocka: Check if 'struct timespec' is available.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 761af94..7f8c11d 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -4,6 +4,7 @@
 include(CheckLibraryExists)
 include(CheckTypeSize)
 include(CheckCXXSourceCompiles)
+include(CheckStructHasMember)
 include(TestBigEndian)
 
 set(PACKAGE ${APPLICATION_NAME})
@@ -64,6 +65,9 @@
 check_include_file(time.h HAVE_TIME_H)
 check_include_file(unistd.h HAVE_UNISTD_H)
 
+if (HAVE_TIME_H)
+    check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
+endif (HAVE_TIME_H)
 
 # FUNCTIONS
 check_function_exists(calloc HAVE_CALLOC)
@@ -114,7 +118,7 @@
 }" HAVE_MSVC_THREAD_LOCAL_STORAGE)
 endif(WIN32)
 
-if (HAVE_TIME_H AND HAVE_CLOCK_GETTIME)
+if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
     set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
 
     message(STATUS "CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES} CMAKE_REQUIRED_LIBRARIES=${CMAKE_REQUIRED_LIBRARIES}")
@@ -129,7 +133,7 @@
     return 0;
 }" HAVE_CLOCK_GETTIME_REALTIME)
     set(CMAKE_REQUIRED_INCLUDES)
-endif (HAVE_TIME_H AND HAVE_CLOCK_GETTIME)
+endif ()
 
 # ENDIAN
 if (NOT WIN32)
diff --git a/config.h.cmake b/config.h.cmake
index aa691d0..e657024 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -68,6 +68,10 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #cmakedefine HAVE_UNISTD_H 1
 
+/**************************** STRUCTS ****************************/
+
+#cmakedefine HAVE_STRUCT_TIMESPEC 1
+
 /*************************** FUNCTIONS ***************************/
 
 /* Define to 1 if you have the `calloc' function. */
diff --git a/src/cmocka.c b/src/cmocka.c
index 56ac54a..9e52015 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -2232,6 +2232,7 @@
  * TIME CALCULATIONS
  ****************************************************************************/
 
+#ifdef HAVE_STRUCT_TIMESPEC
 static struct timespec cm_tspecdiff(struct timespec time1,
                                     struct timespec time0)
 {
@@ -2275,6 +2276,7 @@
 
     return ret;
 }
+#endif /* HAVE_STRUCT_TIMESPEC */
 
 /****************************************************************************
  * CMOCKA TEST RUNNER
@@ -2401,6 +2403,7 @@
 
 static int cmocka_run_one_tests(struct CMUnitTestState *test_state)
 {
+#ifdef HAVE_STRUCT_TIMESPEC
     struct timespec start = {
         .tv_sec = 0,
         .tv_nsec = 0,
@@ -2409,6 +2412,7 @@
         .tv_sec = 0,
         .tv_nsec = 0,
     };
+#endif
     int rc = 0;
 
     /* Run setup */
@@ -2429,7 +2433,9 @@
     }
 
     /* Run test */
+#ifdef HAVE_STRUCT_TIMESPEC
     CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &start);
+#endif
 
     if (rc == 0) {
         rc = cmocka_run_one_test_or_fixture(test_state->test->name,
@@ -2451,8 +2457,12 @@
         rc = 0;
     }
 
+    test_state->runtime = 0.0;
+
+#ifdef HAVE_STRUCT_TIMESPEC
     CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &finish);
     test_state->runtime = cm_secdiff(finish, start);
+#endif
 
     /* Run teardown */
     if (rc == 0 && test_state->test->teardown_func != NULL) {