diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-05-25 22:08:31 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-05-25 22:13:28 +0200 |
commit | 36abd82a7e41477245f6c3e06bcf53e0c5e35b03 (patch) | |
tree | 813b04e36d7fbf165a556baede5281980647810e | |
parent | fd6d0b6897813ef9978c8714cf4ce37d8a8b179f (diff) | |
download | libssh-36abd82a7e41477245f6c3e06bcf53e0c5e35b03.tar.gz libssh-36abd82a7e41477245f6c3e06bcf53e0c5e35b03.tar.xz libssh-36abd82a7e41477245f6c3e06bcf53e0c5e35b03.zip |
cmake: Fix detection of clock_gettime.
-rw-r--r-- | ConfigureChecks.cmake | 13 | ||||
-rw-r--r-- | config.h.cmake | 3 | ||||
-rw-r--r-- | src/misc.c | 14 |
3 files changed, 16 insertions, 14 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 683c8eb5..b2774776 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -107,11 +107,13 @@ if (UNIX) # librt check_library_exists(rt nanosleep "" HAVE_LIBRT) - if (HAVE_LIBRT) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt) - endif (HAVE_LIBRT) endif (NOT LINUX) + check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME) + if (HAVE_LIBRT OR HAVE_CLOCK_GETTIME) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt) + endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME) + check_function_exists(getaddrinfo HAVE_GETADDRINFO) check_function_exists(poll HAVE_POLL) check_function_exists(select HAVE_SELECT) @@ -119,11 +121,6 @@ if (UNIX) check_function_exists(regcomp HAVE_REGCOMP) endif (UNIX) -check_library_exists(rt clock_gettime "" HAVE_LIBRT) -if (HAVE_LIBRT) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt) -endif (HAVE_LIBRT) - set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries") # LIBRARIES diff --git a/config.h.cmake b/config.h.cmake index 462f513d..9c2e98ca 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -77,6 +77,9 @@ /* Define to 1 if you have the `regcomp' function. */ #cmakedefine HAVE_REGCOMP 1 +/* Define to 1 if you have the `clock_gettime' function. */ +#cmakedefine HAVE_CLOCK_GETTIME 1 + /*************************** LIBRARIES ***************************/ /* Define to 1 if you have the `crypto' library (-lcrypto). */ @@ -42,7 +42,7 @@ #include <sys/types.h> #include <ctype.h> #include <time.h> -#ifndef HAVE_RT +#ifndef HAVE_CLOCK_GETTIME #include <sys/time.h> #endif @@ -872,18 +872,20 @@ int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2) { * @param[out] ts pointer to an allocated ssh_timestamp structure */ void ssh_timestamp_init(struct ssh_timestamp *ts){ -#ifndef HAVE_RT - struct timeval tp; - gettimeofday(&tp, NULL); - ts->useconds = tp.tv_usec; -#else +#ifdef HAVE_CLOCK_GETTIME struct timespec tp; clock_gettime(CLOCK, &tp); ts->useconds = tp.tv_nsec / 1000; +#else + struct timeval tp; + gettimeofday(&tp, NULL); + ts->useconds = tp.tv_usec; #endif ts->seconds = tp.tv_sec; } +#undef CLOCK + /** * @internal * @brief gets the time difference between two timestamps in ms |