diff options
author | dimitri staessens <[email protected]> | 2017-08-10 22:56:12 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2017-08-11 11:52:09 +0200 |
commit | aecf3810c22ac5e904b0eb7bfe26e3168f3f4f43 (patch) | |
tree | 89cb20e426cb3977337e1d16bdb0a445622d6f75 /src/lib | |
parent | 2b42b1e1121dfd715a78502a3652d326330b8160 (diff) | |
download | ouroboros-aecf3810c22ac5e904b0eb7bfe26e3168f3f4f43.tar.gz ouroboros-aecf3810c22ac5e904b0eb7bfe26e3168f3f4f43.zip |
build: Fix compilation on OS X Sierra
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 35 | ||||
-rw-r--r-- | src/lib/bitmap.c | 1 | ||||
-rw-r--r-- | src/lib/hashtable.c | 1 | ||||
-rw-r--r-- | src/lib/random.c | 19 | ||||
-rw-r--r-- | src/lib/shm_rdrbuff.c | 4 | ||||
-rw-r--r-- | src/lib/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/lib/tests/time_utils_test.c | 2 | ||||
-rw-r--r-- | src/lib/time_utils.c | 13 |
8 files changed, 42 insertions, 34 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c6b70d71..550bbc08 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -35,36 +35,42 @@ set(HAVE_ROBUST_MUTEX CACHE STRING "Have robust mutexes") find_library(LIBGCRYPT_LIBRARIES gcrypt) if (LIBGCRYPT_LIBRARIES) - find_path(GCRYPT_INCLUDE_DIR gcrypt.h HINTS /usr/include /usr/local/include) - if (NOT ${GCRYPT_INCLUDE_DIR} STREQUAL "GRYPT_INCLUDE_DIR-NOTFOUND") - file(STRINGS ${GCRYPT_INCLUDE_DIR}/gcrypt.h GCSTR + find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h HINTS /usr/include /usr/local/include) + if (NOT LIBGCRYPT_INCLUDE_DIR STREQUAL "GRYPT_INCLUDE_DIR-NOTFOUND") + file(STRINGS ${LIBGCRYPT_INCLUDE_DIR}/gcrypt.h GCSTR REGEX "^#define GCRYPT_VERSION ") string(REGEX REPLACE "^#define GCRYPT_VERSION \"(.*)\".*$" "\\1" GCVER "${GCSTR}") message(STATUS "Found libgcrypt: ${LIBGCRYPT_LIBRARIES} (found version \"${GCVER}\")") if (NOT GCVER VERSION_LESS "1.7.0") - include_directories(${GCRYPT_INCLUDE_DIR}) set(HAVE_LIBGCRYPT "1" CACHE STRING "Have libgcrypt") endif() endif () else () - set(LIBGCRYPT_LIBRARIES "") + set(LIBGCRYPT_LIBRARIES "") + set(LIBGCRYPT_INCLUDE_DIR "") endif () find_package(OpenSSL) if (OPENSSL_FOUND) - include_directories(${OPENSSL_INCLUDE_DIR}) set(HAVE_OPENSSL "1" CACHE STRING "Have OpenSSL") +else () + set (OPENSSL_INCLUDE_DIR "") endif () -find_path(LINUX_RND_HDR sys/random.h HINTS /usr/include/ /usr/local/include/) -if (NOT ${LINUX_RND_HDR} STREQUAL "LINUX_RND_HDR-NOTFOUND") - message(STATUS "Found sys/random.h in ${LINUX_RND_HDR}") - include_directories(${LINUX_RND_HDR}) - set(HAVE_SYS_RANDOM "1" CACHE STRING "Have Random Header") -endif () +if (APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(SYS_RND_HDR "") +else () + find_path(SYS_RND_HDR sys/random.h PATH /usr/include/ /usr/local/include/) + if (NOT SYS_RND_HDR STREQUAL "SYS_RND_HDR-NOTFOUND") + message(STATUS "Found sys/random.h in ${SYS_RND_HDR}") + set(HAVE_SYS_RANDOM "1" CACHE STRING "Have random header") + else () + set(SYS_RND_HDR "") + endif () +endif() -if (NOT ((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR +if (NOT ((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR APPLE OR HAVE_SYS_RANDOM OR HAVE_OPENSSL OR HAVE_LIBGCRYPT)) message(FATAL_ERROR "No secure random generator found, " "please install libgcrypt (> 1.7.0) or OpenSSL" @@ -117,6 +123,7 @@ target_link_libraries(ouroboros ${LIBRT_LIBRARIES} install(TARGETS ouroboros LIBRARY DESTINATION usr/lib) -target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR} + ${SYS_RND_HDR} ${LIBGCRYPT_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}) add_subdirectory(tests) diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index ec663ec7..ce1a3ee9 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -22,6 +22,7 @@ */ #include <ouroboros/bitmap.h> + #include <assert.h> #include <stdlib.h> #include <string.h> diff --git a/src/lib/hashtable.c b/src/lib/hashtable.c index 77b56075..2b49ecba 100644 --- a/src/lib/hashtable.c +++ b/src/lib/hashtable.c @@ -21,7 +21,6 @@ * 02110-1301 USA */ -#include <ouroboros/config.h> #include <ouroboros/hashtable.h> #include <ouroboros/list.h> #include <ouroboros/errno.h> diff --git a/src/lib/random.c b/src/lib/random.c index 17973695..4ce378cd 100644 --- a/src/lib/random.c +++ b/src/lib/random.c @@ -24,10 +24,20 @@ #include <ouroboros/config.h> #include <ouroboros/random.h> -#if defined(HAVE_SYS_RANDOM) +#if defined(__APPLE__) /* Barf */ +#undef __OSX_AVAILABLE +#define __OSX_AVAILABLE(arg) +#undef __IOS_AVAILABLE +#define __IOS_AVAILABLE(arg) +#undef __TVOS_AVAILABLE +#define __TVOS_AVAILABLE(arg) +#undef __WATCHOS_AVAILABLE +#define __WATCHOS_AVAILABLE(arg) +#include <sys/random.h> +#elif defined(HAVE_SYS_RANDOM) #include <sys/random.h> #elif defined(HAVE_LIBGCRYPT) -#include <grypt.h> +#include <gcrypt.h> #elif defined(__FreeBSD__) #include <stdlib.h> #elif defined(HAVE_OPENSSL) @@ -43,10 +53,13 @@ int random_buffer(void * buf, #elif defined(HAVE_LIBGCRYPT) return gcry_randomize(buf, len, GCRY_STRONG_RANDOM); #elif defined(__FreeBSD__) - return arc4random_buf(buf, len); + arc4random_buf(buf, len); + return 0; #elif defined(HAVE_OPENSSL) if (len > 0 && len < INT_MAX) return RAND_bytes((unsigned char *) buf, (int) len); return -1; +#elif defined(__APPLE__) + return getentropy(buf, len); #endif } diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index d454fef8..59f32056 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -123,11 +123,11 @@ static char * rdrb_filename(void) { char * str; - str = malloc(strlen(SHM_RDRB_PREFIX) + 1); + str = malloc(strlen(SHM_RDRB_NAME) + 1); if (str == NULL) return NULL; - sprintf(str, "%s", SHM_RDRB_PREFIX); + sprintf(str, "%s", SHM_RDRB_NAME); return str; } diff --git a/src/lib/tests/CMakeLists.txt b/src/lib/tests/CMakeLists.txt index 46a3e91f..41c2074a 100644 --- a/src/lib/tests/CMakeLists.txt +++ b/src/lib/tests/CMakeLists.txt @@ -14,6 +14,7 @@ create_test_sourcelist(${PARENT_DIR}_tests test_suite.c ) add_executable(${PARENT_DIR}_test EXCLUDE_FROM_ALL ${${PARENT_DIR}_tests}) + target_link_libraries(${PARENT_DIR}_test ouroboros) add_dependencies(check ${PARENT_DIR}_test) diff --git a/src/lib/tests/time_utils_test.c b/src/lib/tests/time_utils_test.c index 86636c15..2878132b 100644 --- a/src/lib/tests/time_utils_test.c +++ b/src/lib/tests/time_utils_test.c @@ -33,7 +33,7 @@ static void ts_print(struct timespec * s) static void tv_print(struct timeval * v) { - printf("timeval is %zd:%ld.\n", (ssize_t) v->tv_sec, v->tv_usec); + printf("timeval is %zd:%zu.\n", (ssize_t) v->tv_sec, (size_t) v->tv_usec); } static void ts_init(struct timespec * s, diff --git a/src/lib/time_utils.c b/src/lib/time_utils.c index 07994af2..c644c889 100644 --- a/src/lib/time_utils.c +++ b/src/lib/time_utils.c @@ -142,16 +142,3 @@ int ts_to_tv(const struct timespec * src, return 0; } - -#ifdef __APPLE__ -int clock_gettime(int clock, - struct timespec * t) -{ - struct timeval tv; - int ret = gettimeofday(&tv, NULL); - t->tv_sec = tv.tv_sec; - t->tv_nsec = tv.tv_usec * 1000; - (void) clock; - return ret; -} -#endif |